services

package
v0.0.0-...-6857a66 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthenticationRequired = errors.New("authentication_required")
	ErrConsentRequired        = errors.New("consent_required")
	ErrAbortAuthorize         = errors.New("abort")
)
View Source
var ErrClientNotFound = errors.New("client not found")
View Source
var ErrRevokedAccessToken = errors.New("access_token is revoked")
View Source
var ErrRevokedRefreshToken = errors.New("refresh_token is revoked")

Functions

This section is empty.

Types

type AccessTokenService

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

func NewAccessTokenService

func NewAccessTokenService(accessTokenRepository *repositories.AccessTokenRepository, clientRepository *repositories.ClientRepository, userRepository *repositories.UserRepository, meta *metadata.ServerMetadata, cryp *CryptoService, keys *JWKService) *AccessTokenService

func (*AccessTokenService) Create

func (*AccessTokenService) Delete

func (a *AccessTokenService) Delete(ctx context.Context, id string) error

func (*AccessTokenService) DeleteAll

func (a *AccessTokenService) DeleteAll(ctx context.Context, request *dto.DeleteAccessTokens) error

func (*AccessTokenService) Get

func (a *AccessTokenService) Get(ctx context.Context, signedToken string) (*dto.AccessToken, error)

func (*AccessTokenService) GetAud

func (a *AccessTokenService) GetAud(ctx context.Context, token jwt.Token) ([]string, error)

Extract audience from a jwt.Token; errors are thrown if the token did not contain a known audience

func (*AccessTokenService) GetClientID

func (a *AccessTokenService) GetClientID(ctx context.Context, token jwt.Token) (string, error)

Extract client_id from a jwt.Token; errors are thrown if the token did not contain a client_id string

func (*AccessTokenService) GetJti

func (a *AccessTokenService) GetJti(ctx context.Context, token jwt.Token) (string, error)

Extract jti from a jwt.Token; errors are thrown if the token did not contain a jti

func (*AccessTokenService) GetScope

func (a *AccessTokenService) GetScope(token jwt.Token) (*scope.Scope, error)

Extract scope from a jwt.Token; errors are thrown if the token did not contain a scope

func (*AccessTokenService) GetSub

func (a *AccessTokenService) GetSub(ctx context.Context, token jwt.Token) (string, error)

Extract sub from a jwt.Token; errors are thrown if the token did not contain a sub

func (*AccessTokenService) HasRequiredScopes

func (a *AccessTokenService) HasRequiredScopes(token jwt.Token, required *scope.Scope) bool

func (*AccessTokenService) IsRevoked

func (a *AccessTokenService) IsRevoked(ctx context.Context, token jwt.Token) bool

func (*AccessTokenService) RevokeAll

func (a *AccessTokenService) RevokeAll(ctx context.Context, request *dto.RevokeAccessTokens) error

type AuthenticationService

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

func NewAuthenticationService

func NewAuthenticationService(userService *UserService) *AuthenticationService

func (*AuthenticationService) GetUserFromSession

func (a *AuthenticationService) GetUserFromSession(c *gin.Context) (*dto.User, error)

func (*AuthenticationService) Login

func (a *AuthenticationService) Login(c *gin.Context, request *dto.LoginRequest) error

func (*AuthenticationService) Register

func (a *AuthenticationService) Register(ctx context.Context, request *dto.RegisterRequest) error

type AuthorizationCodeResponse

type AuthorizationCodeResponse struct {
	RedirectURI string
}

type AuthorizationCodeService

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

func NewAuthorizationCodeService

func NewAuthorizationCodeService(rdb *redis.Client, keys *JWKService) *AuthorizationCodeService

func (*AuthorizationCodeService) Create

func (*AuthorizationCodeService) Delete

func (s *AuthorizationCodeService) Delete(ctx context.Context, code string) error

func (*AuthorizationCodeService) Get

type AuthorizeError

type AuthorizeError struct {
	Err         string
	Description string
	RedirectURI string
}

func (AuthorizeError) Error

func (a AuthorizeError) Error() string

type ClientService

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

func NewClientService

func NewClientService(clientRepository *repositories.ClientRepository) *ClientService

func (*ClientService) Authenticate

func (cs *ClientService) Authenticate(ctx context.Context, credentials *oalib.ClientCredentials) (*dto.Client, *oalib.VerboseError)

func (*ClientService) CheckSecret

func (cs *ClientService) CheckSecret(client *dto.Client, secret string) bool

func (*ClientService) Get

func (cs *ClientService) Get(ctx context.Context, id string) (*dto.Client, error)

func (*ClientService) GetAll

func (cs *ClientService) GetAll(ctx context.Context) ([]*dto.Client, error)

func (*ClientService) GetFromURL

func (cs *ClientService) GetFromURL(ctx context.Context, u string) (*dto.Client, error)

func (*ClientService) GetMany

func (cs *ClientService) GetMany(ctx context.Context, ids ...string) ([]*dto.Client, error)

func (*ClientService) ParseCredentials

func (cs *ClientService) ParseCredentials(c *gin.Context) (*oalib.ClientCredentials, *oalib.VerboseError)

func (*ClientService) Register

func (cs *ClientService) Register(ctx context.Context, request *dto.ClientRegister) error

type ConsentService

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

func NewConsentService

func NewConsentService(consentRepository *repositories.ConsentRepository) *ConsentService

func (*ConsentService) Create

func (cs *ConsentService) Create(ctx context.Context, consent *dto.Consent) error

func (*ConsentService) Get

func (cs *ConsentService) Get(ctx context.Context, consent *dto.Consent) (*dto.Consent, error)

func (*ConsentService) GetAll

func (cs *ConsentService) GetAll(ctx context.Context, userID string) (*dto.UserConsents, error)

func (*ConsentService) HasConsent

func (cs *ConsentService) HasConsent(ctx context.Context, consent *dto.Consent) bool

func (*ConsentService) Revoke

func (cs *ConsentService) Revoke(ctx context.Context, consent *dto.Consent) error

type CreatedTokens

type CreatedTokens struct {
	AccessToken  string
	RefreshToken string
	Scope        string
	ExpiresIn    int
}

type CryptoService

type CryptoService struct{}

func NewCryptoService

func NewCryptoService() *CryptoService

func (CryptoService) Decrypt

func (c CryptoService) Decrypt(data []byte, key []byte) ([]byte, error)

func (CryptoService) Encrypt

func (c CryptoService) Encrypt(data []byte, key []byte) []byte

type JWKService

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

func NewJWKService

func NewJWKService() *JWKService

func (JWKService) KeyProviderfunc

func (j JWKService) KeyProviderfunc(ctx context.Context, sink jws.KeySink, sig *jws.Signature, msg *jws.Message) error

func (JWKService) Keys

func (j JWKService) Keys() jwk.Set

func (JWKService) PrivateKey

func (j JWKService) PrivateKey() jwk.Key

func (JWKService) PublicKey

func (j JWKService) PublicKey() jwk.Key

func (JWKService) PublicKeys

func (j JWKService) PublicKeys() jwk.Set

type OAuthService

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

func NewOAuthService

func NewOAuthService(
	meta *metadata.ServerMetadata,
	authenticationService *AuthenticationService,
	clientService *ClientService,
	consentService *ConsentService,
	tokenService *TokenService,
	jwkService *JWKService,
	authorizationCodeService *AuthorizationCodeService,
) *OAuthService

func (*OAuthService) Authorize

Authorize services authorization requests.

func (*OAuthService) JWKs

func (oa *OAuthService) JWKs() jwk.Set

func (*OAuthService) Metadata

func (oa *OAuthService) Metadata() *metadata.ServerMetadata

func (*OAuthService) Register

Register services dynamic client registration. We don't authenticate clients as defined in rfc7591 (OAuth 2.0 Dynamic Client Registration Protocol). We only implement it as an easy way to configure the respective client(s). Thus, instead of having an open registration or using pre-defined access tokens for the clients we use a pre-defined allowlist of client_ids and a pre-shared secret in a custom header.

func (*OAuthService) Revoke

func (oa *OAuthService) Revoke(c *gin.Context, request *dto.OAuthRevoke) *oalib.VerboseError

Revoke services token revocation. https://www.rfc-editor.org/rfc/rfc7009

func (*OAuthService) Token

Token services token requests.

type ProfileService

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

func NewProfileService

func NewProfileService(userRepository *repositories.UserRepository) *ProfileService

func (*ProfileService) Update

func (p *ProfileService) Update(ctx context.Context, request *dto.UpdateProfile) error

type RefreshTokenService

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

func NewRefreshTokenService

func NewRefreshTokenService(refreshTokenRepository *repositories.RefreshTokenRepository, cryp *CryptoService, keys *JWKService) *RefreshTokenService

func (*RefreshTokenService) Create

func (*RefreshTokenService) Get

func (r *RefreshTokenService) Get(ctx context.Context, signedToken string) (*dto.RefreshToken, error)

func (*RefreshTokenService) RevokeAll

func (r *RefreshTokenService) RevokeAll(ctx context.Context, request *dto.RevokeRefreshTokens) error

type TokenService

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

func (*TokenService) CreateTokens

func (t *TokenService) CreateTokens(ctx context.Context, request *dto.CreateTokens) *CreatedTokens

func (*TokenService) GetFromRequest

func (t *TokenService) GetFromRequest(c *gin.Context) (*dto.AccessToken, error)

func (*TokenService) GetUnverifiedFromRequest

func (t *TokenService) GetUnverifiedFromRequest(c *gin.Context) jwt.Token

func (*TokenService) HasRequiredScopes

func (t *TokenService) HasRequiredScopes(accessToken jwt.Token, required *scope.Scope) bool

func (*TokenService) ParseAccessToken

func (t *TokenService) ParseAccessToken(ctx context.Context, signedToken string) (*dto.AccessToken, error)

func (*TokenService) RefreshTokens

func (t *TokenService) RefreshTokens(ctx context.Context, request *dto.RefreshTokens) (*CreatedTokens, error)

RefreshTokens refreshes an access token.

func (*TokenService) Revoke

func (t *TokenService) Revoke(ctx context.Context, request *dto.RevokeTokens) *oalib.VerboseError

Revoke services token revocations.

func (*TokenService) RevokeAll

func (t *TokenService) RevokeAll(ctx context.Context, clientID string, userID string) error

type UserService

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

func NewUserService

func NewUserService(repository *repositories.UserRepository) *UserService

func (UserService) Exists

func (u UserService) Exists(ctx context.Context, username string) bool

func (UserService) Get

func (u UserService) Get(ctx context.Context, id string) (*dto.User, error)

func (UserService) GetByUsername

func (u UserService) GetByUsername(ctx context.Context, username string) (*dto.User, error)

func (UserService) Register

func (u UserService) Register(ctx context.Context, request *dto.RegisterRequest) error

Jump to

Keyboard shortcuts

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