mirror of
https://github.com/harness/drone.git
synced 2025-05-06 16:42:31 +08:00

This change introduces the concept of a principal (abstraction of call identity), and adds a new service account type principal. Also adds support for different tokens (session, PAT, SAT, OAuth2) and adds auth.Session which is being used to capture information about the caller and call method.
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
// Copyright 2022 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by the Polyform Free Trial License
|
|
// that can be found in the LICENSE.md file for this repository.
|
|
|
|
package authn
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/harness/gitness/internal/auth"
|
|
)
|
|
|
|
var (
|
|
// ErrNoAuthData that is returned if the authorizer doesn't find any data in the request that can be used for auth.
|
|
ErrNoAuthData = errors.New("the request doesn't contain any auth data that can be used by the Authorizer")
|
|
)
|
|
|
|
// Authenticator is an abstraction of an entity that's responsible for authenticating principals
|
|
// that are making calls via HTTP.
|
|
type Authenticator interface {
|
|
/*
|
|
* Tries to authenticate the acting principal if credentials are available.
|
|
* Returns:
|
|
* (session, nil) - request contains auth data and principal was verified
|
|
* (nil, ErrNoAuthData) - request doesn't contain any auth data
|
|
* (nil, err) - request contains auth data but verification failed
|
|
*/
|
|
Authenticate(r *http.Request) (*auth.Session, error)
|
|
}
|