Documentation
¶
Index ¶
- Constants
- Variables
- func AuthMethods(c Configuration) []string
- func AuthRequestError(w http.ResponseWriter, r *http.Request, authReq ErrAuthRequest, err error, ...)
- func AuthResponse(authReq AuthRequest, authorizer Authorizer, w http.ResponseWriter, ...)
- func AuthResponseCode(w http.ResponseWriter, r *http.Request, authReq AuthRequest, ...)
- func AuthResponseToken(w http.ResponseWriter, r *http.Request, authReq AuthRequest, ...)
- func Authorize(w http.ResponseWriter, r *http.Request, authorizer Authorizer)
- func AuthorizeCallback(w http.ResponseWriter, r *http.Request, authorizer Authorizer)
- func AuthorizeClient(ctx context.Context, tokenReq *oidc.AccessTokenRequest, exchanger Exchanger) (AuthRequest, Client, error)
- func AuthorizeClientIDSecret(ctx context.Context, clientID, clientSecret string, storage OPStorage) error
- func BuildAuthRequestCode(authReq AuthRequest, crypto Crypto) (string, error)
- func CodeChallengeMethods(c Configuration) []string
- func CodeExchange(w http.ResponseWriter, r *http.Request, exchanger Exchanger)
- func ContainsResponseType(types []oidc.ResponseType, responseType oidc.ResponseType) bool
- func CreateAccessToken(ctx context.Context, tokenRequest TokenRequest, ...) (token string, validity time.Duration, err error)
- func CreateAuthRequestCode(ctx context.Context, authReq AuthRequest, storage Storage, crypto Crypto) (string, error)
- func CreateBearerToken(tokenID, subject string, crypto Crypto) (string, error)
- func CreateDiscoveryConfig(c Configuration, s Signer) *oidc.DiscoveryConfiguration
- func CreateIDToken(ctx context.Context, issuer string, authReq AuthRequest, ...) (string, error)
- func CreateJWT(ctx context.Context, issuer string, tokenRequest TokenRequest, exp time.Time, ...) (string, error)
- func CreateJWTTokenResponse(ctx context.Context, tokenRequest TokenRequest, creator TokenCreator) (*oidc.AccessTokenResponse, error)
- func CreateRouter(o OpenIDProvider, interceptors ...HttpInterceptor) *mux.Router
- func CreateTokenResponse(ctx context.Context, authReq AuthRequest, client Client, creator TokenCreator, ...) (*oidc.AccessTokenResponse, error)
- func Discover(w http.ResponseWriter, config *oidc.DiscoveryConfiguration)
- func EndSession(w http.ResponseWriter, r *http.Request, ender SessionEnder)
- func EnsureKey(ctx context.Context, storage Storage, keyCh chan<- jose.SigningKey, ...)
- func GrantTypes(c Configuration) []string
- func IsConfidentialType(c Client) bool
- func JWTProfile(w http.ResponseWriter, r *http.Request, ...)
- func Keys(w http.ResponseWriter, r *http.Request, k KeyProvider)
- func NeedsExistingSession(authRequest *oidc.AuthRequest) bool
- func ParseAccessTokenRequest(r *http.Request, decoder utils.Decoder) (*oidc.AccessTokenRequest, error)
- func ParseAuthorizeRequest(r *http.Request, decoder utils.Decoder) (*oidc.AuthRequest, error)
- func ParseEndSessionRequest(r *http.Request, decoder utils.Decoder) (*oidc.EndSessionRequest, error)
- func ParseJWTProfileRequest(r *http.Request, decoder utils.Decoder) (*tokenexchange.JWTProfileRequest, error)
- func ParseTokenExchangeRequest(w http.ResponseWriter, r *http.Request) (oidc.TokenRequest, error)
- func Readiness(w http.ResponseWriter, r *http.Request, probes ...ProbesFn)
- func RedirectToLogin(authReqID string, client Client, w http.ResponseWriter, r *http.Request)
- func RequestError(w http.ResponseWriter, r *http.Request, err error)
- func ResponseTypes(c Configuration) []string
- func Scopes(c Configuration) []string
- func SigAlgorithms(s Signer) []string
- func SubjectTypes(c Configuration) []string
- func SupportedClaims(c Configuration) []string
- func TokenExchange(w http.ResponseWriter, r *http.Request, exchanger Exchanger)
- func Userinfo(w http.ResponseWriter, r *http.Request, userinfoProvider UserinfoProvider)
- func ValidateAccessTokenRequest(ctx context.Context, tokenReq *oidc.AccessTokenRequest, exchanger Exchanger) (AuthRequest, Client, error)
- func ValidateAuthReqIDTokenHint(ctx context.Context, idTokenHint string, verifier IDTokenHintVerifier) (string, error)
- func ValidateAuthReqRedirectURI(client Client, uri string, responseType oidc.ResponseType) error
- func ValidateAuthReqResponseType(client Client, responseType oidc.ResponseType) error
- func ValidateAuthReqScopes(client Client, scopes []string) ([]string, error)
- func ValidateAuthRequest(ctx context.Context, authReq *oidc.AuthRequest, storage Storage, ...) (string, error)
- func ValidateIssuer(issuer string) error
- func ValidateTokenExchangeRequest(tokenReq oidc.TokenRequest, storage Storage) error
- func VerifyAccessToken(ctx context.Context, token string, v AccessTokenVerifier) (oidc.AccessTokenClaims, error)
- func VerifyIDTokenHint(ctx context.Context, token string, v IDTokenHintVerifier) (oidc.IDTokenClaims, error)
- func VerifyJWTAssertion(ctx context.Context, profileRequest *tokenexchange.JWTProfileRequest, ...) (*oidc.JWTTokenRequest, error)
- type AccessTokenType
- type AccessTokenVerifier
- type ApplicationType
- type AuthMethod
- type AuthRequest
- type AuthStorage
- type AuthorizeValidator
- type Authorizer
- type Client
- type Config
- type Configuration
- type Crypto
- type EndSessionRequest
- type Endpoint
- type ErrAuthRequest
- type Exchanger
- type HttpInterceptor
- type IDTokenHintVerifier
- type JWTAuthorizationGrantExchanger
- type JWTProfileVerifier
- type KeyProvider
- type OAuthError
- type OPStorage
- type OpenIDProvider
- type Option
- func WithCustomAuthEndpoint(endpoint Endpoint) Option
- func WithCustomEndSessionEndpoint(endpoint Endpoint) Option
- func WithCustomEndpoints(auth, token, userInfo, endSession, keys Endpoint) Option
- func WithCustomKeysEndpoint(endpoint Endpoint) Option
- func WithCustomTokenEndpoint(endpoint Endpoint) Option
- func WithCustomUserinfoEndpoint(endpoint Endpoint) Option
- func WithHttpInterceptors(interceptors ...HttpInterceptor) Option
- func WithRetry(max int, sleep time.Duration) Option
- func WithTimer(timer <-chan time.Time) Option
- type ProbesFn
- type SessionEnder
- type Signer
- type Storage
- type StorageNotFoundError
- type TokenCreator
- type TokenRequest
- type UserinfoProvider
Constants ¶
const ( InvalidRequest errorType = "invalid_request" InvalidRequestURI errorType = "invalid_request_uri" InteractionRequired errorType = "interaction_required" ServerError errorType = "server_error" )
const OidcDevMode = "CAOS_OIDC_DEV"
Variables ¶
var ( ErrInvalidRequest = func(description string) *OAuthError { return &OAuthError{ ErrorType: InvalidRequest, Description: description, } } ErrInvalidRequestRedirectURI = func(description string) *OAuthError { return &OAuthError{ ErrorType: InvalidRequestURI, Description: description, redirectDisabled: true, } } ErrInteractionRequired = func(description string) *OAuthError { return &OAuthError{ ErrorType: InteractionRequired, Description: description, } } ErrServerError = func(description string) *OAuthError { return &OAuthError{ ErrorType: ServerError, Description: description, } } )
var ( DefaultEndpoints = &endpoints{ Authorization: NewEndpoint(defaultAuthorizationEndpoint), Token: NewEndpoint(defaulTokenEndpoint), Introspection: NewEndpoint(defaultIntrospectEndpoint), Userinfo: NewEndpoint(defaultUserinfoEndpoint), EndSession: NewEndpoint(defaultEndSessionEndpoint), JwksURI: NewEndpoint(defaultKeysEndpoint), } )
var DefaultSupportedScopes = []string{ oidc.ScopeOpenID, oidc.ScopeProfile, oidc.ScopeEmail, oidc.ScopePhone, oidc.ScopeAddress, }
Functions ¶
func AuthMethods ¶
func AuthMethods(c Configuration) []string
func AuthRequestError ¶
func AuthRequestError(w http.ResponseWriter, r *http.Request, authReq ErrAuthRequest, err error, encoder utils.Encoder)
func AuthResponse ¶
func AuthResponse(authReq AuthRequest, authorizer Authorizer, w http.ResponseWriter, r *http.Request)
AuthResponse creates the successful authentication response (either code or tokens)
func AuthResponseCode ¶
func AuthResponseCode(w http.ResponseWriter, r *http.Request, authReq AuthRequest, authorizer Authorizer)
AuthResponseCode creates the successful code authentication response
func AuthResponseToken ¶
func AuthResponseToken(w http.ResponseWriter, r *http.Request, authReq AuthRequest, authorizer Authorizer, client Client)
AuthResponseToken creates the successful token(s) authentication response
func Authorize ¶
func Authorize(w http.ResponseWriter, r *http.Request, authorizer Authorizer)
Authorize handles the authorization request, including parsing, validating, storing and finally redirecting to the login handler
func AuthorizeCallback ¶
func AuthorizeCallback(w http.ResponseWriter, r *http.Request, authorizer Authorizer)
AuthorizeCallback handles the callback after authentication in the Login UI
func AuthorizeClient ¶
func AuthorizeClient(ctx context.Context, tokenReq *oidc.AccessTokenRequest, exchanger Exchanger) (AuthRequest, Client, error)
func AuthorizeClientIDSecret ¶
func BuildAuthRequestCode ¶
func BuildAuthRequestCode(authReq AuthRequest, crypto Crypto) (string, error)
func CodeChallengeMethods ¶ added in v0.7.1
func CodeChallengeMethods(c Configuration) []string
func CodeExchange ¶
func CodeExchange(w http.ResponseWriter, r *http.Request, exchanger Exchanger)
func ContainsResponseType ¶ added in v0.7.0
func ContainsResponseType(types []oidc.ResponseType, responseType oidc.ResponseType) bool
func CreateAccessToken ¶
func CreateAccessToken(ctx context.Context, tokenRequest TokenRequest, accessTokenType AccessTokenType, creator TokenCreator, client Client) (token string, validity time.Duration, err error)
func CreateAuthRequestCode ¶ added in v0.6.2
func CreateAuthRequestCode(ctx context.Context, authReq AuthRequest, storage Storage, crypto Crypto) (string, error)
CreateAuthRequestCode creates and stores a code for the auth code response
func CreateBearerToken ¶
func CreateDiscoveryConfig ¶
func CreateDiscoveryConfig(c Configuration, s Signer) *oidc.DiscoveryConfiguration
func CreateIDToken ¶
func CreateJWTTokenResponse ¶ added in v0.9.0
func CreateJWTTokenResponse(ctx context.Context, tokenRequest TokenRequest, creator TokenCreator) (*oidc.AccessTokenResponse, error)
func CreateRouter ¶
func CreateRouter(o OpenIDProvider, interceptors ...HttpInterceptor) *mux.Router
func CreateTokenResponse ¶
func CreateTokenResponse(ctx context.Context, authReq AuthRequest, client Client, creator TokenCreator, createAccessToken bool, code string) (*oidc.AccessTokenResponse, error)
func Discover ¶
func Discover(w http.ResponseWriter, config *oidc.DiscoveryConfiguration)
func EndSession ¶ added in v0.4.0
func EndSession(w http.ResponseWriter, r *http.Request, ender SessionEnder)
func GrantTypes ¶
func GrantTypes(c Configuration) []string
func IsConfidentialType ¶
func JWTProfile ¶ added in v0.9.0
func JWTProfile(w http.ResponseWriter, r *http.Request, exchanger JWTAuthorizationGrantExchanger)
func Keys ¶
func Keys(w http.ResponseWriter, r *http.Request, k KeyProvider)
func NeedsExistingSession ¶
func NeedsExistingSession(authRequest *oidc.AuthRequest) bool
func ParseAccessTokenRequest ¶
func ParseAuthorizeRequest ¶ added in v0.7.5
ParseAuthorizeRequest parsed the http request into a AuthRequest
func ParseEndSessionRequest ¶ added in v0.4.0
func ParseJWTProfileRequest ¶ added in v0.9.0
func ParseJWTProfileRequest(r *http.Request, decoder utils.Decoder) (*tokenexchange.JWTProfileRequest, error)
func ParseTokenExchangeRequest ¶
func ParseTokenExchangeRequest(w http.ResponseWriter, r *http.Request) (oidc.TokenRequest, error)
func Readiness ¶ added in v0.2.1
func Readiness(w http.ResponseWriter, r *http.Request, probes ...ProbesFn)
func RedirectToLogin ¶
RedirectToLogin redirects the end user to the Login UI for authentication
func RequestError ¶ added in v0.4.0
func RequestError(w http.ResponseWriter, r *http.Request, err error)
func ResponseTypes ¶
func ResponseTypes(c Configuration) []string
func Scopes ¶
func Scopes(c Configuration) []string
func SigAlgorithms ¶
func SubjectTypes ¶
func SubjectTypes(c Configuration) []string
func SupportedClaims ¶
func SupportedClaims(c Configuration) []string
func TokenExchange ¶
func TokenExchange(w http.ResponseWriter, r *http.Request, exchanger Exchanger)
func Userinfo ¶
func Userinfo(w http.ResponseWriter, r *http.Request, userinfoProvider UserinfoProvider)
func ValidateAccessTokenRequest ¶
func ValidateAccessTokenRequest(ctx context.Context, tokenReq *oidc.AccessTokenRequest, exchanger Exchanger) (AuthRequest, Client, error)
func ValidateAuthReqIDTokenHint ¶ added in v0.5.0
func ValidateAuthReqIDTokenHint(ctx context.Context, idTokenHint string, verifier IDTokenHintVerifier) (string, error)
ValidateAuthReqIDTokenHint validates the id_token_hint (if passed as parameter in the request) and returns the `sub` claim
func ValidateAuthReqRedirectURI ¶
func ValidateAuthReqRedirectURI(client Client, uri string, responseType oidc.ResponseType) error
ValidateAuthReqRedirectURI validates the passed redirect_uri and response_type to the registered uris and client type
func ValidateAuthReqResponseType ¶
func ValidateAuthReqResponseType(client Client, responseType oidc.ResponseType) error
ValidateAuthReqResponseType validates the passed response_type to the registered response types
func ValidateAuthReqScopes ¶
ValidateAuthReqScopes validates the passed scopes
func ValidateAuthRequest ¶
func ValidateAuthRequest(ctx context.Context, authReq *oidc.AuthRequest, storage Storage, verifier IDTokenHintVerifier) (string, error)
ValidateAuthRequest validates the authorize parameters and returns the userID of the id_token_hint if passed
func ValidateIssuer ¶
func ValidateTokenExchangeRequest ¶
func ValidateTokenExchangeRequest(tokenReq oidc.TokenRequest, storage Storage) error
func VerifyAccessToken ¶ added in v0.12.0
func VerifyAccessToken(ctx context.Context, token string, v AccessTokenVerifier) (oidc.AccessTokenClaims, error)
VerifyAccessToken validates the access token (issuer, signature and expiration)
func VerifyIDTokenHint ¶ added in v0.9.0
func VerifyIDTokenHint(ctx context.Context, token string, v IDTokenHintVerifier) (oidc.IDTokenClaims, error)
VerifyIDTokenHint validates the id token according to https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation
func VerifyJWTAssertion ¶ added in v0.9.0
func VerifyJWTAssertion(ctx context.Context, profileRequest *tokenexchange.JWTProfileRequest, v JWTProfileVerifier) (*oidc.JWTTokenRequest, error)
Types ¶
type AccessTokenType ¶
type AccessTokenType int
const ( AccessTokenTypeBearer AccessTokenType = iota AccessTokenTypeJWT )
type AccessTokenVerifier ¶ added in v0.12.0
type AccessTokenVerifier interface {
oidc.Verifier
SupportedSignAlgs() []string
KeySet() oidc.KeySet
}
func NewAccessTokenVerifier ¶ added in v0.12.0
func NewAccessTokenVerifier(issuer string, keySet oidc.KeySet) AccessTokenVerifier
type ApplicationType ¶
type ApplicationType int
const ( ApplicationTypeWeb ApplicationType = iota ApplicationTypeUserAgent ApplicationTypeNative )
type AuthMethod ¶
type AuthMethod string
const ( AuthMethodBasic AuthMethod = "client_secret_basic" AuthMethodPost AuthMethod = "client_secret_post" AuthMethodNone AuthMethod = "none" CodeMethodS256 = "S256" )
type AuthRequest ¶
type AuthRequest interface {
GetID() string
GetACR() string
GetAMR() []string
GetAudience() []string
GetAuthTime() time.Time
GetClientID() string
GetCodeChallenge() *oidc.CodeChallenge
GetNonce() string
GetRedirectURI() string
GetResponseType() oidc.ResponseType
GetScopes() []string
GetState() string
GetSubject() string
Done() bool
}
func AuthorizeCodeChallenge ¶
func AuthorizeCodeChallenge(ctx context.Context, tokenReq *oidc.AccessTokenRequest, exchanger Exchanger) (AuthRequest, error)
type AuthStorage ¶
type AuthStorage interface {
CreateAuthRequest(context.Context, *oidc.AuthRequest, string) (AuthRequest, error)
AuthRequestByID(context.Context, string) (AuthRequest, error)
AuthRequestByCode(context.Context, string) (AuthRequest, error)
SaveAuthCode(context.Context, string, string) error
DeleteAuthRequest(context.Context, string) error
CreateToken(context.Context, TokenRequest) (string, time.Time, error)
TerminateSession(context.Context, string, string) error
GetSigningKey(context.Context, chan<- jose.SigningKey, chan<- error, <-chan time.Time)
GetKeySet(context.Context) (*jose.JSONWebKeySet, error)
SaveNewKeyPair(context.Context) error
}
type AuthorizeValidator ¶ added in v0.7.5
type AuthorizeValidator interface {
Authorizer
ValidateAuthRequest(context.Context, *oidc.AuthRequest, Storage, IDTokenHintVerifier) (string, error)
}
AuthorizeValidator is an extension of Authorizer interface implementing it's own validation mechanism for the auth request
type Authorizer ¶
type Client ¶
type Client interface {
GetID() string
RedirectURIs() []string
PostLogoutRedirectURIs() []string
ApplicationType() ApplicationType
AuthMethod() AuthMethod
ResponseTypes() []oidc.ResponseType
LoginURL(string) string
AccessTokenType() AccessTokenType
IDTokenLifetime() time.Duration
DevMode() bool
RestrictAdditionalIdTokenScopes() func(scopes []string) []string
RestrictAdditionalAccessTokenScopes() func(scopes []string) []string
IsScopeAllowed(scope string) bool
IDTokenUserinfoClaimsAssertion() bool
ClockSkew() time.Duration
}
type Configuration ¶
type Configuration interface {
Issuer() string
AuthorizationEndpoint() Endpoint
TokenEndpoint() Endpoint
UserinfoEndpoint() Endpoint
EndSessionEndpoint() Endpoint
KeysEndpoint() Endpoint
AuthMethodPostSupported() bool
CodeMethodS256Supported() bool
GrantTypeTokenExchangeSupported() bool
GrantTypeJWTAuthorizationSupported() bool
}
type Crypto ¶
func NewAESCrypto ¶
type EndSessionRequest ¶ added in v0.4.0
func ValidateEndSessionRequest ¶ added in v0.4.0
func ValidateEndSessionRequest(ctx context.Context, req *oidc.EndSessionRequest, ender SessionEnder) (*EndSessionRequest, error)
type Endpoint ¶
type Endpoint struct {
// contains filtered or unexported fields
}
func NewEndpoint ¶ added in v0.2.4
func NewEndpointWithURL ¶ added in v0.2.4
type ErrAuthRequest ¶
type ErrAuthRequest interface {
GetRedirectURI() string
GetResponseType() oidc.ResponseType
GetState() string
}
type IDTokenHintVerifier ¶ added in v0.9.0
type IDTokenHintVerifier interface {
oidc.Verifier
SupportedSignAlgs() []string
KeySet() oidc.KeySet
ACR() oidc.ACRVerifier
MaxAge() time.Duration
}
func NewIDTokenHintVerifier ¶ added in v0.9.0
func NewIDTokenHintVerifier(issuer string, keySet oidc.KeySet) IDTokenHintVerifier
type JWTAuthorizationGrantExchanger ¶ added in v0.12.2
type JWTAuthorizationGrantExchanger interface {
Exchanger
JWTProfileVerifier() JWTProfileVerifier
}
type JWTProfileVerifier ¶ added in v0.9.0
func NewJWTProfileVerifier ¶ added in v0.9.0
func NewJWTProfileVerifier(storage Storage, issuer string, maxAgeIAT, offset time.Duration) JWTProfileVerifier
type KeyProvider ¶
type KeyProvider interface {
Storage() Storage
}
type OAuthError ¶
type OAuthError struct {
ErrorType errorType `json:"error" schema:"error"`
Description string `json:"error_description,omitempty" schema:"error_description,omitempty"`
State string `json:"state,omitempty" schema:"state,omitempty"`
// contains filtered or unexported fields
}
func (*OAuthError) Error ¶
func (e *OAuthError) Error() string
type OPStorage ¶
type OPStorage interface {
GetClientByClientID(ctx context.Context, clientID string) (Client, error)
AuthorizeClientIDSecret(ctx context.Context, clientID, clientSecret string) error
GetUserinfoFromScopes(ctx context.Context, userID, clientID string, scopes []string) (oidc.UserInfo, error)
GetUserinfoFromToken(ctx context.Context, tokenID, subject, origin string) (oidc.UserInfo, error)
GetPrivateClaimsFromScopes(ctx context.Context, userID, clientID string, scopes []string) (map[string]interface{}, error)
GetKeyByIDAndUserID(ctx context.Context, keyID, userID string) (*jose.JSONWebKey, error)
}
type OpenIDProvider ¶
type OpenIDProvider interface {
Configuration
Storage() Storage
Decoder() utils.Decoder
Encoder() utils.Encoder
IDTokenHintVerifier() IDTokenHintVerifier
AccessTokenVerifier() AccessTokenVerifier
Crypto() Crypto
DefaultLogoutRedirectURI() string
Signer() Signer
Probes() []ProbesFn
HttpHandler() http.Handler
}
func NewOpenIDProvider ¶ added in v0.9.0
type Option ¶ added in v0.9.0
type Option func(o *openidProvider) error
func WithCustomAuthEndpoint ¶
func WithCustomEndSessionEndpoint ¶ added in v0.4.1
func WithCustomEndpoints ¶ added in v0.9.0
func WithCustomKeysEndpoint ¶ added in v0.2.3
func WithCustomTokenEndpoint ¶
func WithHttpInterceptors ¶ added in v0.7.4
func WithHttpInterceptors(interceptors ...HttpInterceptor) Option
type ProbesFn ¶ added in v0.2.1
func ReadySigner ¶ added in v0.2.1
func ReadyStorage ¶ added in v0.2.1
type SessionEnder ¶ added in v0.4.0
type SessionEnder interface {
Decoder() utils.Decoder
Storage() Storage
IDTokenHintVerifier() IDTokenHintVerifier
DefaultLogoutRedirectURI() string
}
type Signer ¶
type StorageNotFoundError ¶ added in v0.2.1
type StorageNotFoundError interface {
IsNotFound()
}
type TokenCreator ¶
type TokenRequest ¶ added in v0.9.0
type UserinfoProvider ¶
type UserinfoProvider interface {
Decoder() utils.Decoder
Crypto() Crypto
Storage() Storage
AccessTokenVerifier() AccessTokenVerifier
}