Documentation
¶
Index ¶
- Constants
- func GetOAuthGroupsForUser(ctx context.Context, user *user_model.User, onlyPublicGroups bool) ([]string, error)
- func GrantAdditionalScopes(grantScopes string) auth.AccessTokenScope
- func Init(ctx context.Context) error
- func InitSigningKey() error
- func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, ...) (*AccessTokenResponse, *AccessTokenError)
- type AccessTokenError
- type AccessTokenErrorCode
- type AccessTokenResponse
- type ErrInvalidAlgorithmType
- type JWTSigningKey
- type OIDCToken
- type Token
- type TokenKind
- type TokenType
Constants ¶
const ( // AccessTokenErrorCodeInvalidRequest represents an error code specified in RFC 6749 AccessTokenErrorCodeInvalidRequest AccessTokenErrorCode = "invalid_request" // AccessTokenErrorCodeInvalidClient represents an error code specified in RFC 6749 AccessTokenErrorCodeInvalidClient = "invalid_client" // AccessTokenErrorCodeInvalidGrant represents an error code specified in RFC 6749 AccessTokenErrorCodeInvalidGrant = "invalid_grant" AccessTokenErrorCodeUnauthorizedClient = "unauthorized_client" // AccessTokenErrorCodeUnsupportedGrantType represents an error code specified in RFC 6749 AccessTokenErrorCodeUnsupportedGrantType = "unsupported_grant_type" // AccessTokenErrorCodeInvalidScope represents an error code specified in RFC 6749 AccessTokenErrorCodeInvalidScope = "invalid_scope" )
Variables ¶
This section is empty.
Functions ¶
func GetOAuthGroupsForUser ¶
func GetOAuthGroupsForUser(ctx context.Context, user *user_model.User, onlyPublicGroups bool) ([]string, error)
returns a list of "org" and "org:team" strings, that the given user is a part of.
func GrantAdditionalScopes ¶
func GrantAdditionalScopes(grantScopes string) auth.AccessTokenScope
GrantAdditionalScopes returns valid scopes coming from grant
func InitSigningKey ¶
func InitSigningKey() error
InitSigningKey creates the default signing key from settings or creates a random key.
func NewAccessTokenResponse ¶
func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, serverKey, clientKey JWTSigningKey) (*AccessTokenResponse, *AccessTokenError)
Types ¶
type AccessTokenError ¶
type AccessTokenError struct {
ErrorCode AccessTokenErrorCode `json:"error" form:"error"`
ErrorDescription string `json:"error_description"`
}
AccessTokenError represents an error response specified in RFC 6749 https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
func (AccessTokenError) Error ¶
func (err AccessTokenError) Error() string
Error returns the error message
type AccessTokenErrorCode ¶
type AccessTokenErrorCode string
AccessTokenErrorCode represents an error code specified in RFC 6749 https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
type AccessTokenResponse ¶
type AccessTokenResponse struct {
AccessToken string `json:"access_token"`
TokenType TokenType `json:"token_type"`
ExpiresIn int64 `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
IDToken string `json:"id_token,omitempty"`
}
AccessTokenResponse represents a successful access token response https://datatracker.ietf.org/doc/html/rfc6749#section-4.2.2
type ErrInvalidAlgorithmType ¶
type ErrInvalidAlgorithmType struct {
Algorithm string
}
ErrInvalidAlgorithmType represents an invalid algorithm error.
func (ErrInvalidAlgorithmType) Error ¶
func (err ErrInvalidAlgorithmType) Error() string
type JWTSigningKey ¶
type JWTSigningKey interface {
IsSymmetric() bool
SigningMethod() jwt.SigningMethod
SignKey() any
VerifyKey() any
ToJWK() (map[string]string, error)
PreProcessToken(*jwt.Token)
}
JWTSigningKey represents a algorithm/key pair to sign JWTs
var DefaultSigningKey JWTSigningKey
DefaultSigningKey is the default signing key for JWTs.
func CreateJWTSigningKey ¶
func CreateJWTSigningKey(algorithm string, key any) (JWTSigningKey, error)
CreateJWTSigningKey creates a signing key from an algorithm / key pair.
type OIDCToken ¶
type OIDCToken struct {
jwt.RegisteredClaims
Nonce string `json:"nonce,omitempty"`
// Scope profile
Name string `json:"name,omitempty"`
PreferredUsername string `json:"preferred_username,omitempty"`
Profile string `json:"profile,omitempty"`
Picture string `json:"picture,omitempty"`
Website string `json:"website,omitempty"`
Locale string `json:"locale,omitempty"`
UpdatedAt timeutil.TimeStamp `json:"updated_at,omitempty"`
// Scope email
Email string `json:"email,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
// Groups are generated by organization and team names
Groups []string `json:"groups,omitempty"`
}
OIDCToken represents an OpenID Connect id_token
type Token ¶
type Token struct {
GrantID int64 `json:"gnt"`
Kind TokenKind `json:"tt"`
Counter int64 `json:"cnt,omitempty"`
jwt.RegisteredClaims
}
Token represents a JWT token used to authenticate a client
func ParseToken ¶
func ParseToken(jwtToken string, signingKey JWTSigningKey) (*Token, error)
ParseToken parses a signed jwt string