auth

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package auth provides the authentication logic for the application

Index

Constants

View Source
const (

	// AuthOAuth2GrantTypeAuthorizationCode is the OAuth2 grant type Authorization Code
	AuthOAuth2GrantTypeAuthorizationCode oauthGrantType
	// AuthOAuth2GrantTypeClientCredentials is the OAuth2 grant type Client Credentials
	AuthOAuth2GrantTypeClientCredentials
	// AuthOAuth2GrantTypePassword is the OAuth2 grant type Password
	AuthOAuth2GrantTypePassword
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyAuthenticator

type APIKeyAuthenticator struct {
	APIKey     string
	HeaderName string
}

APIKeyAuthenticator is an Authenticator that uses API Key

func (*APIKeyAuthenticator) Authenticate

func (a *APIKeyAuthenticator) Authenticate(_ context.Context, _ store.Store) error

Authenticate authenticates the user

func (*APIKeyAuthenticator) GetAuthValue

func (a *APIKeyAuthenticator) GetAuthValue() *pb.Auth

GetAuthValue returns the authentication value

func (*APIKeyAuthenticator) IsExpired

func (a *APIKeyAuthenticator) IsExpired(_ context.Context, _ store.Store) bool

IsExpired checks if the authentication information is expired

func (*APIKeyAuthenticator) Refresh

Refresh refreshes the authentication information

func (*APIKeyAuthenticator) SetOnRequest

func (a *APIKeyAuthenticator) SetOnRequest(_ context.Context, r *http.Request)

SetOnRequest sets the authentication information on the request

type Authenticator

type Authenticator interface {
	SetAuthor
	// Authenticate authenticates the user
	Authenticate(ctx context.Context, str store.Store) error
	// IsExpired checks if the authentication information is expired
	IsExpired(ctx context.Context, str store.Store) bool
	// Refresh refreshes the authentication information
	Refresh(ctx context.Context, str store.Store) error
}

Authenticator is an interface for authenticating

func NewAPIKeyAuthenticator

func NewAPIKeyAuthenticator(conf config.ValidAuthAPIKeyConfig) (Authenticator, error)

NewAPIKeyAuthenticator creates a new APIKeyAuthenticator

func NewBasicAuthenticator

func NewBasicAuthenticator(conf config.ValidAuthBasicConfig) (Authenticator, error)

NewBasicAuthenticator creates a new BasicAuthenticator

func NewJWTAuthenticator

func NewJWTAuthenticator(conf config.ValidAuthJWTConfig) (Authenticator, error)

NewJWTAuthenticator creates a new JWTAuthenticator

func NewOAuthAuthenticator

func NewOAuthAuthenticator(
	str store.Store,
	redirectPort int,
	conf config.ValidAuthOAuth2Config,
) (Authenticator, error)

NewOAuthAuthenticator creates a new OAuthAuthenticator

type AuthenticatorContainer

type AuthenticatorContainer struct {
	DefaultAuthenticator string
	Container            map[string]*Authenticator
}

AuthenticatorContainer holds the dependencies for the Authenticator

func NewAuthenticatorContainerFromConfig

func NewAuthenticatorContainerFromConfig(str store.Store, conf config.ValidConfig) (AuthenticatorContainer, error)

NewAuthenticatorContainerFromConfig creates a new AuthenticatorContainer from the configuration

type BasicAuthenticator

type BasicAuthenticator struct {
	Username string
	Password string
}

BasicAuthenticator is an Authenticator that uses Basic Auth

func (*BasicAuthenticator) Authenticate

func (a *BasicAuthenticator) Authenticate(_ context.Context, _ store.Store) error

Authenticate authenticates the user

func (*BasicAuthenticator) GetAuthValue

func (a *BasicAuthenticator) GetAuthValue() *pb.Auth

GetAuthValue returns the authentication value

func (*BasicAuthenticator) IsExpired

func (a *BasicAuthenticator) IsExpired(_ context.Context, _ store.Store) bool

IsExpired checks if the authentication information is expired

func (*BasicAuthenticator) Refresh

Refresh refreshes the authentication information

func (*BasicAuthenticator) SetOnRequest

func (a *BasicAuthenticator) SetOnRequest(_ context.Context, r *http.Request)

SetOnRequest sets the authentication information on the request

type JWTAuthenticator

type JWTAuthenticator struct {
	// contains filtered or unexported fields
}

JWTAuthenticator is an Authenticator that uses Private Key

func (*JWTAuthenticator) Authenticate

func (a *JWTAuthenticator) Authenticate(_ context.Context, _ store.Store) error

Authenticate authenticates the user

func (*JWTAuthenticator) GetAuthValue

func (a *JWTAuthenticator) GetAuthValue() *pb.Auth

GetAuthValue returns the authentication value

func (*JWTAuthenticator) IsExpired

func (a *JWTAuthenticator) IsExpired(_ context.Context, _ store.Store) bool

IsExpired checks if the authentication information is expired

func (*JWTAuthenticator) Refresh

func (a *JWTAuthenticator) Refresh(_ context.Context, _ store.Store) error

Refresh refreshes the authentication information

func (*JWTAuthenticator) SetOnRequest

func (a *JWTAuthenticator) SetOnRequest(_ context.Context, _ *http.Request)

SetOnRequest sets the authentication information on the request

type OAuthAuthenticator

type OAuthAuthenticator struct {
	// contains filtered or unexported fields
}

OAuthAuthenticator is an Authenticator that uses OAuth

func (*OAuthAuthenticator) Authenticate

func (a *OAuthAuthenticator) Authenticate(ctx context.Context, str store.Store) error

Authenticate authenticates the user

func (*OAuthAuthenticator) GetAuthValue

func (a *OAuthAuthenticator) GetAuthValue() *pb.Auth

GetAuthValue returns the authentication value

func (*OAuthAuthenticator) IsExpired

func (a *OAuthAuthenticator) IsExpired(_ context.Context, _ store.Store) bool

IsExpired checks if the authentication information is expired

func (*OAuthAuthenticator) Refresh

func (a *OAuthAuthenticator) Refresh(ctx context.Context, str store.Store) error

Refresh refreshes the authentication information

func (*OAuthAuthenticator) SetOnRequest

func (a *OAuthAuthenticator) SetOnRequest(ctx context.Context, r *http.Request)

SetOnRequest sets the authentication information on the request

type OAuthToken

type OAuthToken struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	TokenType    string    `json:"token_type"`
	Expiry       time.Time `json:"expiry"`
}

OAuthToken is the OAuth token

func (*OAuthToken) GetAuthValue

func (t *OAuthToken) GetAuthValue() *pb.Auth

GetAuthValue returns the authentication value

func (*OAuthToken) SetOnRequest

func (t *OAuthToken) SetOnRequest(_ context.Context, r *http.Request)

SetOnRequest sets the authentication information on the request

type SetAuthor

type SetAuthor interface {
	// SetOnRequest sets the authentication information on the request
	SetOnRequest(ctx context.Context, r *http.Request)
	// GetAuthValue returns the authentication value
	GetAuthValue() *pb.Auth
}

SetAuthor sets the author on the request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL