auth

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeysDependencies

type APIKeysDependencies struct {
	Logger       zerolog.Logger
	APIKeysStore providers.APIKeysStorer
	Clock        providers.Clock
}

APIKeysDependencies defines the dependencies for the apikeys provider.

type APIKeysProvider

type APIKeysProvider struct {
	APIKeysDependencies
}

APIKeysProvider is the authentication provider for api keys.

func NewAPIKeysProvider

func NewAPIKeysProvider(deps APIKeysDependencies) *APIKeysProvider

NewAPIKeysProvider creates a new authentication provider for api keys.

func (*APIKeysProvider) Encrypt

func (a *APIKeysProvider) Encrypt(ctx context.Context, secret []byte) ([]byte, error)

Encrypt takes an api key secret and encrypts it for storage.

func (*APIKeysProvider) Generate

func (a *APIKeysProvider) Generate(ctx context.Context, name string, userID int) (*models.APIKey, error)

Generate a secret and a key ID pair.

func (*APIKeysProvider) Match

func (a *APIKeysProvider) Match(ctx context.Context, key *models.APIKey) error

Match matches a given user's api keys with the stored ones.

type OAuthAuthenticator

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

OAuthAuthenticator is the OAuthAuthenticator that uses OAuth2 to authenticate the user.

func NewOAuthAuthenticator

NewOAuthAuthenticator creates a new OAuthAuthenticator.

func (*OAuthAuthenticator) Exchange

func (op *OAuthAuthenticator) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

Exchange exchanges the code returned from the OAuth2 authentication URL for a valid token. We then call the TokenIssuer to get an internal JWT.

func (*OAuthAuthenticator) GenerateState

func (op *OAuthAuthenticator) GenerateState(redirectURL string) (string, error)

GenerateState generates the state nonce JWT with expiry.

func (*OAuthAuthenticator) GetAuthCodeURL

func (op *OAuthAuthenticator) GetAuthCodeURL(state string) string

GetAuthCodeURL gets the OAuth2 authentication URL.

func (*OAuthAuthenticator) VerifyState

func (op *OAuthAuthenticator) VerifyState(rawToken string) (string, error)

VerifyState verifies the state nonce JWT.

type OAuthAuthenticatorConfig

type OAuthAuthenticatorConfig struct {
	BaseURL            string
	GoogleClientID     string
	GoogleClientSecret string
	GlobalTokenKey     string
}

OAuthAuthenticatorConfig contains the config for the OAuthAuthenticator.

type OAuthAuthenticatorDependencies

type OAuthAuthenticatorDependencies struct {
	UUID      providers.UUIDGenerator
	Clock     providers.Clock
	Issuer    providers.TokenIssuer
	UserStore providers.UserStorer
}

OAuthAuthenticatorDependencies contains the dependencies for the OAuthAuthenticator.

type RepoAuth

type RepoAuth struct {
	RepositoryAuthDependencies
}

RepoAuth is the authentication provider for Krok repositories.

func NewRepositoryAuth

func NewRepositoryAuth(deps RepositoryAuthDependencies) *RepoAuth

NewRepositoryAuth creates a new repository authentication provider.

func (*RepoAuth) CreateRepositoryAuth

func (a *RepoAuth) CreateRepositoryAuth(ctx context.Context, repositoryID int, info *models.Auth) error

CreateRepositoryAuth creates auth data for a repository in vault.

func (*RepoAuth) GetRepositoryAuth

func (a *RepoAuth) GetRepositoryAuth(ctx context.Context, id int) (*models.Auth, error)

GetRepositoryAuth returns auth data for a repository. Returns ErrNotFound if there is no auth info for a repository.

type RepositoryAuthDependencies

type RepositoryAuthDependencies struct {
	Logger zerolog.Logger
	Vault  providers.Vault
}

RepositoryAuthDependencies defines the dependencies for the repository auth provider.

type TokenIssuer

type TokenIssuer struct {
	TokenIssuerConfig
	TokenIssuerDependencies
}

TokenIssuer represents the auth JWT token issuer.

func NewTokenIssuer

func NewTokenIssuer(cfg TokenIssuerConfig, deps TokenIssuerDependencies) *TokenIssuer

NewTokenIssuer creates a new TokenIssuer.

func (*TokenIssuer) Create

func (ti *TokenIssuer) Create(user *models.User) (*oauth2.Token, error)

Create creates a JWT access_token and refresh_token with the given user details. It will attempt to get or create the user in the database.

func (*TokenIssuer) Refresh

func (ti *TokenIssuer) Refresh(ctx context.Context, refreshToken string) (*oauth2.Token, error)

Refresh refreshes the users JWT tokens.

type TokenIssuerConfig

type TokenIssuerConfig struct {
	GlobalTokenKey string
}

TokenIssuerConfig contains the config for the TokenIssuer.

type TokenIssuerDependencies

type TokenIssuerDependencies struct {
	UserStore providers.UserStorer
	Clock     providers.Clock
}

TokenIssuerDependencies contains the TokenIssuer dependencies.

type TokenProvider

type TokenProvider struct {
	TokenProviderDependencies
}

TokenProvider is the provider which saves and manages tokens for the various platforms.

func NewPlatformTokenProvider

func NewPlatformTokenProvider(deps TokenProviderDependencies) *TokenProvider

NewPlatformTokenProvider creates a new Token provider for the platforms.

func (*TokenProvider) GetTokenForPlatform

func (t *TokenProvider) GetTokenForPlatform(vcs int) (string, error)

GetTokenForPlatform will retrieve the token for this VCS.

func (*TokenProvider) SaveTokenForPlatform

func (t *TokenProvider) SaveTokenForPlatform(token string, vcs int) error

SaveTokenForPlatform will save the token for this VCS.

type TokenProviderDependencies

type TokenProviderDependencies struct {
	Logger zerolog.Logger
	Vault  providers.Vault
}

TokenProviderDependencies defines the dependencies for the token provider.

Jump to

Keyboard shortcuts

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