Documentation ¶
Index ¶
- Variables
- type AccessTokenService
- func (a *AccessTokenService) Create(ctx context.Context, request *dto.CreateAccessToken) (*dto.AccessToken, error)
- func (a *AccessTokenService) Delete(ctx context.Context, id string) error
- func (a *AccessTokenService) DeleteAll(ctx context.Context, request *dto.DeleteAccessTokens) error
- func (a *AccessTokenService) Get(ctx context.Context, signedToken string) (*dto.AccessToken, error)
- func (a *AccessTokenService) GetAud(ctx context.Context, token jwt.Token) ([]string, error)
- func (a *AccessTokenService) GetClientID(ctx context.Context, token jwt.Token) (string, error)
- func (a *AccessTokenService) GetJti(ctx context.Context, token jwt.Token) (string, error)
- func (a *AccessTokenService) GetScope(token jwt.Token) (*scope.Scope, error)
- func (a *AccessTokenService) GetSub(ctx context.Context, token jwt.Token) (string, error)
- func (a *AccessTokenService) HasRequiredScopes(token jwt.Token, required *scope.Scope) bool
- func (a *AccessTokenService) IsRevoked(ctx context.Context, token jwt.Token) bool
- func (a *AccessTokenService) RevokeAll(ctx context.Context, request *dto.RevokeAccessTokens) error
- type AuthenticationService
- type AuthorizationCodeResponse
- type AuthorizationCodeService
- func (s *AuthorizationCodeService) Create(ctx context.Context, request *dto.CreateAuthorizationCode) (*oalib.AuthorizationCode, error)
- func (s *AuthorizationCodeService) Delete(ctx context.Context, code string) error
- func (s *AuthorizationCodeService) Get(ctx context.Context, code string) (*oalib.AuthorizationCode, error)
- type AuthorizeError
- type ClientService
- func (cs *ClientService) Authenticate(ctx context.Context, credentials *oalib.ClientCredentials) (*dto.Client, *oalib.VerboseError)
- func (cs *ClientService) CheckSecret(client *dto.Client, secret string) bool
- func (cs *ClientService) Get(ctx context.Context, id string) (*dto.Client, error)
- func (cs *ClientService) GetAll(ctx context.Context) ([]*dto.Client, error)
- func (cs *ClientService) GetFromURL(ctx context.Context, u string) (*dto.Client, error)
- func (cs *ClientService) GetMany(ctx context.Context, ids ...string) ([]*dto.Client, error)
- func (cs *ClientService) ParseCredentials(c *gin.Context) (*oalib.ClientCredentials, *oalib.VerboseError)
- func (cs *ClientService) Register(ctx context.Context, request *dto.ClientRegister) error
- type ConsentService
- func (cs *ConsentService) Create(ctx context.Context, consent *dto.Consent) error
- func (cs *ConsentService) Get(ctx context.Context, consent *dto.Consent) (*dto.Consent, error)
- func (cs *ConsentService) GetAll(ctx context.Context, userID string) (*dto.UserConsents, error)
- func (cs *ConsentService) HasConsent(ctx context.Context, consent *dto.Consent) bool
- func (cs *ConsentService) Revoke(ctx context.Context, consent *dto.Consent) error
- type CreatedTokens
- type CryptoService
- type JWKService
- type OAuthService
- func (oa *OAuthService) Authorize(c *gin.Context, request *dto.AuthorizeRequest) (*AuthorizationCodeResponse, error)
- func (oa *OAuthService) JWKs() jwk.Set
- func (oa *OAuthService) Metadata() *metadata.ServerMetadata
- func (oa *OAuthService) Register(ctx context.Context, request dto.OAuthRegisterClient) (*oalib.ClientInformationResponse, *oalib.VerboseError)
- func (oa *OAuthService) Revoke(c *gin.Context, request *dto.OAuthRevoke) *oalib.VerboseError
- func (oa *OAuthService) Token(c *gin.Context, request *dto.TokenRequest) (*oalib.TokenResponse, *oalib.VerboseError)
- type ProfileService
- type RefreshTokenService
- func (r *RefreshTokenService) Create(ctx context.Context, request *dto.CreateRefreshToken) (*dto.RefreshToken, error)
- func (r *RefreshTokenService) Get(ctx context.Context, signedToken string) (*dto.RefreshToken, error)
- func (r *RefreshTokenService) RevokeAll(ctx context.Context, request *dto.RevokeRefreshTokens) error
- type TokenService
- func (t *TokenService) CreateTokens(ctx context.Context, request *dto.CreateTokens) *CreatedTokens
- func (t *TokenService) GetFromRequest(c *gin.Context) (*dto.AccessToken, error)
- func (t *TokenService) GetUnverifiedFromRequest(c *gin.Context) jwt.Token
- func (t *TokenService) HasRequiredScopes(accessToken jwt.Token, required *scope.Scope) bool
- func (t *TokenService) ParseAccessToken(ctx context.Context, signedToken string) (*dto.AccessToken, error)
- func (t *TokenService) RefreshTokens(ctx context.Context, request *dto.RefreshTokens) (*CreatedTokens, error)
- func (t *TokenService) Revoke(ctx context.Context, request *dto.RevokeTokens) *oalib.VerboseError
- func (t *TokenService) RevokeAll(ctx context.Context, clientID string, userID string) error
- type UserService
- func (u UserService) Exists(ctx context.Context, username string) bool
- func (u UserService) Get(ctx context.Context, id string) (*dto.User, error)
- func (u UserService) GetByUsername(ctx context.Context, username string) (*dto.User, error)
- func (u UserService) Register(ctx context.Context, request *dto.RegisterRequest) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthenticationRequired = errors.New("authentication_required") ErrConsentRequired = errors.New("consent_required") ErrAbortAuthorize = errors.New("abort") )
var ErrClientNotFound = errors.New("client not found")
var ErrRevokedAccessToken = errors.New("access_token is revoked")
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 (a *AccessTokenService) Create(ctx context.Context, request *dto.CreateAccessToken) (*dto.AccessToken, error)
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 ¶
Extract audience from a jwt.Token; errors are thrown if the token did not contain a known audience
func (*AccessTokenService) GetClientID ¶
Extract client_id from a jwt.Token; errors are thrown if the token did not contain a client_id string
func (*AccessTokenService) GetJti ¶
Extract jti from a jwt.Token; errors are thrown if the token did not contain a jti
func (*AccessTokenService) GetScope ¶
Extract scope from a jwt.Token; errors are thrown if the token did not contain a scope
func (*AccessTokenService) GetSub ¶
Extract sub from a jwt.Token; errors are thrown if the token did not contain a sub
func (*AccessTokenService) HasRequiredScopes ¶
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 (*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 (s *AuthorizationCodeService) Create(ctx context.Context, request *dto.CreateAuthorizationCode) (*oalib.AuthorizationCode, error)
func (*AuthorizationCodeService) Delete ¶
func (s *AuthorizationCodeService) Delete(ctx context.Context, code string) error
func (*AuthorizationCodeService) Get ¶
func (s *AuthorizationCodeService) Get(ctx context.Context, code string) (*oalib.AuthorizationCode, error)
type AuthorizeError ¶
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) GetFromURL ¶
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) GetAll ¶
func (cs *ConsentService) GetAll(ctx context.Context, userID string) (*dto.UserConsents, error)
func (*ConsentService) HasConsent ¶
type CreatedTokens ¶
type CryptoService ¶
type CryptoService struct{}
func NewCryptoService ¶
func NewCryptoService() *CryptoService
type JWKService ¶
type JWKService struct {
// contains filtered or unexported fields
}
func NewJWKService ¶
func NewJWKService() *JWKService
func (JWKService) KeyProviderfunc ¶
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 ¶
func (oa *OAuthService) Authorize(c *gin.Context, request *dto.AuthorizeRequest) (*AuthorizationCodeResponse, error)
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 ¶
func (oa *OAuthService) Register(ctx context.Context, request dto.OAuthRegisterClient) (*oalib.ClientInformationResponse, *oalib.VerboseError)
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 ¶
func (oa *OAuthService) Token(c *gin.Context, request *dto.TokenRequest) (*oalib.TokenResponse, *oalib.VerboseError)
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 (r *RefreshTokenService) Create(ctx context.Context, request *dto.CreateRefreshToken) (*dto.RefreshToken, error)
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 NewTokenService ¶
func NewTokenService(db *sql.DB, meta *metadata.ServerMetadata, keys *JWKService, cryp *CryptoService, cons *ConsentService, ats *AccessTokenService, rts *RefreshTokenService) *TokenService
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 (*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.
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
func NewUserService ¶
func NewUserService(repository *repositories.UserRepository) *UserService
func (UserService) GetByUsername ¶
func (UserService) Register ¶
func (u UserService) Register(ctx context.Context, request *dto.RegisterRequest) error