auth

package
v0.0.0-...-34f3205 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSignedE2ETestToken

func GenerateSignedE2ETestToken(identity Identity, extraClaims ...ExtraClaim) (string, error)

Types

type ExtraClaim

type ExtraClaim func(token *jwt.Token)

ExtraClaim a function to set claims in the token to generate

func WithAccountIDClaim

func WithAccountIDClaim(accountID string) ExtraClaim

WithAccountIDClaim sets the `account_id` claim in the token to generate

func WithAudClaim

func WithAudClaim(aud []string) ExtraClaim

WithAudClaim sets the `aud` claim in the token to generate

func WithCompanyClaim

func WithCompanyClaim(company string) ExtraClaim

WithCompanyClaim sets the `company` claim in the token to generate

func WithEmailClaim

func WithEmailClaim(email string) ExtraClaim

WithEmailClaim sets the `email` claim in the token to generate

func WithExpClaim

func WithExpClaim(exp time.Time) ExtraClaim

WithExpClaim sets the `exp` claim in the token to generate

func WithFamilyNameClaim

func WithFamilyNameClaim(familyName string) ExtraClaim

WithFamilyNameClaim sets the `familyName` claim in the token to generate

func WithGivenNameClaim

func WithGivenNameClaim(givenName string) ExtraClaim

WithGivenNameClaim sets the `givenName` claim in the token to generate

func WithIATClaim

func WithIATClaim(iat time.Time) ExtraClaim

WithIATClaim sets the `iat` claim in the token to generate

func WithNotBeforeClaim

func WithNotBeforeClaim(nbf time.Time) ExtraClaim

WithNotBeforeClaim sets the `nbf` claim in the token to generate

func WithOriginalSubClaim

func WithOriginalSubClaim(originalSub string) ExtraClaim

WithOriginalSubClaim sets the `original_sub` claim in the token to generate

func WithPreferredUsernameClaim

func WithPreferredUsernameClaim(username string) ExtraClaim

WithPreferredUsernameClaim sets the `preferred username` claim in the token to generate

func WithSubClaim

func WithSubClaim(sub string) ExtraClaim

WithSubClaim sets the `sub` claim in the token to generate

func WithUserIDClaim

func WithUserIDClaim(userID string) ExtraClaim

WithUserIDClaim sets the `user_id` claim in the token to generate

type Identity

type Identity struct {
	ID       uuid.UUID
	Username string
	Email    string
}

Identity is a user identity

func NewIdentity

func NewIdentity() *Identity

NewIdentity returns a new, random identity

type MyClaims

type MyClaims struct {
	jwt.RegisteredClaims
	IdentityID        string `json:"uuid,omitempty"`
	PreferredUsername string `json:"preferred_username,omitempty"`
	SessionState      string `json:"session_state,omitempty"`
	Type              string `json:"typ,omitempty"`
	Approved          bool   `json:"approved,omitempty"`
	Name              string `json:"name,omitempty"`
	Company           string `json:"company,omitempty"`
	GivenName         string `json:"given_name,omitempty"`
	FamilyName        string `json:"family_name,omitempty"`
	Email             string `json:"email,omitempty"`
	EmailVerified     bool   `json:"email_verified,omitempty"`
	OriginalSub       string `json:"original_sub"`
	UserID            string `json:"user_id"`
	AccountID         string `json:"account_id"`
}

type PublicKey

type PublicKey struct {
	KeyID string
	Key   *rsa.PublicKey
}

PublicKey represents an RSA public key with a Key ID

func GetE2ETestPublicKey

func GetE2ETestPublicKey() []*PublicKey

GetE2ETestPublicKey returns the public key and kid used for e2e tests

type TokenManager

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

TokenManager represents the test token and key manager.

func NewTokenManager

func NewTokenManager() *TokenManager

NewTokenManager creates a new TokenManager.

func (*TokenManager) AddPrivateKey

func (tg *TokenManager) AddPrivateKey(kid string) (*rsa.PrivateKey, error)

AddPrivateKey creates and stores a new key with the given kid.

func (*TokenManager) GenerateSignedToken

func (tg *TokenManager) GenerateSignedToken(identity Identity, kid string, extraClaims ...ExtraClaim) (string, error)

GenerateSignedToken generates a JWT user token and signs it using the given private key.

func (*TokenManager) GenerateToken

func (tg *TokenManager) GenerateToken(identity Identity, kid string, extraClaims ...ExtraClaim) *jwt.Token

GenerateToken generates a default token.

func (*TokenManager) Key

func (tg *TokenManager) Key(kid string) (*rsa.PrivateKey, error)

Key retrieves the key associated with the given kid.

func (*TokenManager) NewKeyServer

func (tg *TokenManager) NewKeyServer() *httptest.Server

NewKeyServer creates and starts a http key server

func (*TokenManager) RemovePrivateKey

func (tg *TokenManager) RemovePrivateKey(kid string)

RemovePrivateKey removes a key from the list of known keys.

func (*TokenManager) SignToken

func (tg *TokenManager) SignToken(token *jwt.Token, kid string) (string, error)

SignToken signs a given token using the given private key.

type WebKeySet

type WebKeySet struct {
	Keys []jwk.Key `json:"keys"`
}

WebKeySet represents a JWK Set object.

Jump to

Keyboard shortcuts

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