Documentation ¶
Index ¶
- Constants
- Variables
- func AllowUnauthorized() func(*MiddlewareConfig)
- func NewOAuthMiddleware(svc Service, opts ...func(*MiddlewareConfig)) fiber.Handler
- func WithAuthorized(fn func(*fiber.Ctx, Claims)) func(*MiddlewareConfig)
- func WithConfig(cfg config.Oidc) func(*MiddlewareConfig)
- type Claims
- type FakeProvider
- func (p *FakeProvider) ExchangeCode(ctx context.Context, authCode string) (Claims, *JWT, error)
- func (p *FakeProvider) GenerateState() State
- func (p *FakeProvider) GetAuthURL(state string) string
- func (p *FakeProvider) GetName() string
- func (p *FakeProvider) RevokeToken(ctx context.Context, token *JWT) error
- func (p *FakeProvider) Token(userID string) *JWT
- func (p *FakeProvider) ValidateToken(ctx context.Context, token *JWT) (Claims, error)
- type JWT
- type MiddlewareConfig
- type Provider
- type ProviderOption
- type Providers
- type RedirectURL
- type Service
- type State
- type TimeService
Constants ¶
View Source
const ClaimsContextKey = "claims"
Variables ¶
View Source
var ( ErrNoClaimsInContext = errors.New("no claims in context") ErrInvalidSession = errors.New("invalid or expired session") )
View Source
var ( ErrProviderNoConfig = errors.New("missing provider configuration") ErrProviderInvalidConfig = errors.New("invalid provider configuration") ErrProviderValidateToken = errors.New("provider token validation failed") ErrProviderCodeExchange = errors.New("provider code exchange failed") ErrProviderTokenRevoke = errors.New("provider token revoke failed") ErrProviderAuthInfo = errors.New("provider auth info failed") ErrProviderKeyMissing = errors.New("missing provider key") ErrProviderUnsupported = errors.New("unsupported provider") ErrProviderUnexpectedResponse = errors.New("provider returned unexpected response") )
Functions ¶
func AllowUnauthorized ¶
func AllowUnauthorized() func(*MiddlewareConfig)
func NewOAuthMiddleware ¶
func NewOAuthMiddleware(svc Service, opts ...func(*MiddlewareConfig)) fiber.Handler
func WithAuthorized ¶
func WithAuthorized(fn func(*fiber.Ctx, Claims)) func(*MiddlewareConfig)
func WithConfig ¶
func WithConfig(cfg config.Oidc) func(*MiddlewareConfig)
Types ¶
type Claims ¶
func ClaimsFromCtx ¶
type FakeProvider ¶
type FakeProvider struct {
// contains filtered or unexported fields
}
func NewFakeProvider ¶
func NewFakeProvider(opts ...ProviderOption) *FakeProvider
func (*FakeProvider) ExchangeCode ¶
func (*FakeProvider) GenerateState ¶
func (p *FakeProvider) GenerateState() State
func (*FakeProvider) GetAuthURL ¶
func (p *FakeProvider) GetAuthURL(state string) string
func (*FakeProvider) GetName ¶
func (p *FakeProvider) GetName() string
func (*FakeProvider) RevokeToken ¶
func (p *FakeProvider) RevokeToken(ctx context.Context, token *JWT) error
func (*FakeProvider) Token ¶
func (p *FakeProvider) Token(userID string) *JWT
Token Returns a valid token for the given user ID.
func (*FakeProvider) ValidateToken ¶
type JWT ¶
type JWT struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` IDToken string `json:"id_token"` Scope string `json:"scope"` Type string `json:"token_type"` Provider string `json:"provider"` ExpiresIn int64 `json:"expires_in"` }
func DecodeSession ¶
DecodeSession decode given base64 url encoded JSONWebToken.
type MiddlewareConfig ¶
type MiddlewareConfig struct { // Extractor defines how the token claims are extracted from the request Extractor func(*fiber.Ctx, string) (Claims, error) // Authorized runs after valid claims are found Authorized func(*fiber.Ctx, Claims) // Key name of the session cookie Key string // AllowEmptyCookie allows unauthenticated access if true AllowEmptyCookie bool }
type Provider ¶
type ProviderOption ¶
type ProviderOption func(*FakeProvider)
func WithClaims ¶
func WithClaims(c Claims) ProviderOption
func WithExpire ¶
func WithExpire(timestamp int64) ProviderOption
func WithStateID ¶
func WithStateID(stateID string) ProviderOption
type Providers ¶
type Providers struct {
// contains filtered or unexported fields
}
func NewProviders ¶
type RedirectURL ¶
func NewRedirectURL ¶
func NewRedirectURL(p Provider, state string) (RedirectURL, error)
type Service ¶
type TimeService ¶
func NewFakeTimeService ¶
func NewFakeTimeService(time time.Time) TimeService
func NewTimeService ¶
func NewTimeService() TimeService
Click to show internal directories.
Click to hide internal directories.