oidc

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CookiePrefix        = "cachaca"
	MaxSessionAge       = time.Hour
	SessionKeyBitLength = 512
)
View Source
const (
	MaxSessionKeyLength = 4096
	StateKeyBitLength   = 256
	BitsPerByte         = 8
)

Variables

View Source
var (
	ErrMissingAuthorizationHeader = errors.New("missing authorization header")
	ErrUnknownIssuer              = errors.New("unknown issuer")
	ErrMissingSessionID           = errors.New("missing session id")
)
View Source
var (
	ErrSessionTokenTooLong       = errors.New("session token too long")
	ErrStateMismatch             = errors.New("state mismatch")
	ErrAlgorithmValidationFailed = errors.New("algorithm validation failed")
	ErrTokenHeaderMissing        = errors.New("token header missing")
)
View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Authorizer

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

Authorizer provides an OAuth/OIDC enabled mechanism for verifying the identity of a user through OAuth and OIDC. The authorizer handles the communication and authentication flow with the OAuth/OIDC provider and handles session management.

After authentication with the OAuth/OIDC provider and completing the authentication flow, the clients will have to provide a bearer token or session cookie which will be used to identify the users. This token/cookie is a short-lived JWT with configurable claims. By default, the access token, refresh token and other user information is not stored in the session JWT for security reasons. This behaviour can be overridden by providing a custom SessionCallback.

An `oidc.Credentials` object will be passed into the calling context. It provides the claims from the session JWT. The information received from the OAuth/OIDC provider (such as the access token) can optionally be stored in a pluggable storage interface - and can be lazy-loaded through the provided `oidc.Credentials` object.

func NewAuthorizer

func NewAuthorizer(signingKey *jose.SigningKey, opts ...Option) *Authorizer

func (*Authorizer) Apply

func (authorizer *Authorizer) Apply(server *cachaca.Server) error

func (*Authorizer) AuthorizeGrpc

func (authorizer *Authorizer) AuthorizeGrpc(ctx context.Context) (context.Context, error)

AuthorizeGrpc implements the `auth.Authorizer` interface and injects the session information into the gRPC context.

func (*Authorizer) AuthorizeHTTP

func (authorizer *Authorizer) AuthorizeHTTP(ctx *gin.Context) error

AuthorizeHTTP implements the `auth.Authorizer` interface and injects the session information into the GIN context.

func (*Authorizer) RegisterRelyingParty

func (authorizer *Authorizer) RegisterRelyingParty(name string, relyingParty rp.RelyingParty)

RegisterRelyingParty registers an OAuth/OIDC relying party. The passed name will be used in the login path to identify which provider to use. Please note that the issuer string of the relying party must also be unique and will be used to validate sessions. Therefore all services consuming the session (JWT) token must have the same relying parties configured.

type Credentials

type Credentials struct {
	jwt.Claims
	// contains filtered or unexported fields
}

Credentials represents the (validated) client credentials. It directly exposes the standard JWT claims that were provided by the client. Custom claims can be retrieved using the `GetCustomClaims` method. To reduce calls to the storage backend, credentials lazy loads the OAuth2/OIDC tokens/sessions if requested through the `GetSession` method.

func (*Credentials) GetCustomClaims

func (c *Credentials) GetCustomClaims(claims ...interface{}) error

func (*Credentials) GetProvider

func (c *Credentials) GetProvider() rp.RelyingParty

func (*Credentials) GetSession

func (c *Credentials) GetSession(ctx context.Context) (*Session, error)

func (*Credentials) Refresh

func (c *Credentials) Refresh(ctx context.Context) error

type MemoryStorage

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

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(_ context.Context, sessionID string) error

func (*MemoryStorage) Get

func (s *MemoryStorage) Get(_ context.Context, sessionID string) (*Session, error)

func (*MemoryStorage) Set

func (s *MemoryStorage) Set(_ context.Context, session *Session) error

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithCallbackURL

func WithCallbackURL(url string) Option

func WithErrorURL

func WithErrorURL(url string) Option

func WithLoginURL

func WithLoginURL(url string) Option

func WithLogoutURL

func WithLogoutURL(url string) Option

func WithStorage

func WithStorage(storage Storage) Option

func WithSuccessURL

func WithSuccessURL(url string) Option

func WithTokenCallback

func WithTokenCallback(tokenCallback SessionCallbackFunc) Option

type RedisStorage

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

func NewRedisStorage

func NewRedisStorage(client rueidis.Client, cacheTimeout time.Duration) *RedisStorage

func (*RedisStorage) Delete

func (s *RedisStorage) Delete(ctx context.Context, sessionID string) error

func (*RedisStorage) Get

func (s *RedisStorage) Get(ctx context.Context, sessionID string) (*Session, error)

func (*RedisStorage) Set

func (s *RedisStorage) Set(ctx context.Context, session *Session) error

type Session

type Session struct {
	*oidc.Tokens[*oidc.IDTokenClaims]
	ID       string         `json:"id"`
	UserInfo *oidc.UserInfo `json:"userInfo,omitempty"`
	Issuer   string         `json:"issuer,omitempty"`
	// contains filtered or unexported fields
}

func NewSessionFromCodeExchange

func NewSessionFromCodeExchange(ctx context.Context, code string, provider rp.RelyingParty) (*Session, error)

type SessionCallbackFunc

type SessionCallbackFunc func(ctx context.Context, session *Session) (interface{}, error)

type Storage

type Storage interface {
	Get(ctx context.Context, sessionID string) (*Session, error)
	Set(ctx context.Context, session *Session) error
	Delete(ctx context.Context, sessionID string) error
}

type StorageOptions

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

type TokenCallBackOptions

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

type URLOptions

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

Jump to

Keyboard shortcuts

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