jwtlib

package
v0.0.0-...-0eac02a Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenTypeAccess    = "a"
	TokenTypeRefresh   = "r"
	TokenTypeId        = "i"
	TokenTypeSession   = "s"
	TokenTypeUndefined = "U"
)
View Source
const AccessTokenExpiration = HOUR
View Source
const DAY = HOUR * 24
View Source
const HOUR int64 = 3600
View Source
const IdTokenExpiration = 8 * HOUR
View Source
const LatestPrivateKey = "latest" + PrivateKeyExt
View Source
const PasswordLogin = "pwd-login"
View Source
const PrivateKeyExt = ".pem"
View Source
const PublicKeyExt = ".pub"
View Source
const RefreshTokenExpiration = 7 * DAY // WEEK
View Source
const SessionTokenExpiration = 12 * HOUR

Variables

This section is empty.

Functions

func Exists

func Exists(name string) bool

Exists reports whether the named file or directory exists.

func GenerateAndStoreNewRsaKey

func GenerateAndStoreNewRsaKey(ctx context.Context, basePath, name string) error

func JtiPartsToString

func JtiPartsToString(parts JtiParts) string

Types

type Claims

type Claims struct {
	Audience   string `json:"aud,omitempty"`
	ExpiresAt  int64  `json:"exp,omitempty"`
	Id         string `json:"jti,omitempty"`
	IssuedAt   int64  `json:"iat,omitempty"`
	Issuer     string `json:"iss,omitempty"`
	Subject    string `json:"sub,omitempty"`
	Additional map[string]interface{}
	Scopes     shared.Scopes `json:"scope,omitempty"`
}

func (*Claims) Serialize

func (claims *Claims) Serialize() jwt.MapClaims

type DiProvider

type DiProvider struct {
	Repos    Repositories
	Services Services
	Facade   KeysFacade
}

func NewDiProvider

func NewDiProvider(keyPath string) DiProvider

type JtiParts

type JtiParts struct {
	CorrelationId string
	Type          string
	Offset        string
}

func ParseJtiParts

func ParseJtiParts(str string) (JtiParts, error)

type Jwk

type Jwk interface {
	Algorithm() string
	KeyId() string

	PublicKey() crypto.PublicKey
	PrivateKey() crypto.PrivateKey
}

func LoadRSAKey

func LoadRSAKey(ctx context.Context, basePath string, id string) (Jwk, error)

func NewJwkRsa

func NewJwkRsa(id string, algo string, pubKey *rsa.PublicKey, privKey *rsa.PrivateKey) Jwk

type JwkGenerateParams

type JwkGenerateParams struct {
}

type JwkRepository

type JwkRepository interface {
	Get(ctx context.Context, id string) (Jwk, error)
	List(ctx context.Context) ([]Jwk, error)
	Generate(ctx context.Context, params JwkGenerateParams) error
	Store(ctx context.Context, jwk Jwk) error
	Add(ctx context.Context, jwk Jwk) error
	GetLatest(ctx context.Context) (Jwk, error)
}

func NewJwkRepository

func NewJwkRepository(keysPath string) JwkRepository

type JwkRepositoryImpl

type JwkRepositoryImpl struct {
	BasePath string
	// contains filtered or unexported fields
}

func (*JwkRepositoryImpl) Add

func (repo *JwkRepositoryImpl) Add(ctx context.Context, jwk Jwk) error

func (*JwkRepositoryImpl) Generate

func (repo *JwkRepositoryImpl) Generate(ctx context.Context, params JwkGenerateParams) error

func (*JwkRepositoryImpl) Get

func (repo *JwkRepositoryImpl) Get(ctx context.Context, id string) (Jwk, error)

func (*JwkRepositoryImpl) GetLatest

func (repo *JwkRepositoryImpl) GetLatest(ctx context.Context) (Jwk, error)

func (*JwkRepositoryImpl) List

func (repo *JwkRepositoryImpl) List(ctx context.Context) (result []Jwk, err error)

func (*JwkRepositoryImpl) Store

func (repo *JwkRepositoryImpl) Store(ctx context.Context, jwk Jwk) error

type JwkRsa

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

func (*JwkRsa) Algorithm

func (jwk *JwkRsa) Algorithm() string

func (*JwkRsa) KeyId

func (jwk *JwkRsa) KeyId() string

func (*JwkRsa) PrivateKey

func (jwk *JwkRsa) PrivateKey() crypto.PrivateKey

func (*JwkRsa) PublicKey

func (jwk *JwkRsa) PublicKey() crypto.PublicKey

type JwkService

type JwkService interface {
	GenerateNew(ctx context.Context) error
	List(ctx context.Context) ([]Jwk, error)
	Get(ctx context.Context, id string) (Jwk, error)
	GetLatest(ctx context.Context) (Jwk, error)
}

func NewJwkService

func NewJwkService(jwkRepo JwkRepository) JwkService

type Jwt

type Jwt interface {
	JwkID() string
	ClientId() string
	Audience() string
	Subject() string
	ID() string
	Issuer() string

	IssuedAt() time.Time
	ExpiresAt() time.Time
	UserId() string
	AppId() string
	Scopes() shared.Scopes
	Jti() JtiParts
	Raw() string

	// Kind of internal
	Claims() map[string]interface{}
	RawHeader() map[string]interface{}
}

func NewJwt

func NewJwt(token *jwt.Token) Jwt

type JwtService

type JwtService interface {
	CreateAccessToken(ctx context.Context, params TokenCreateParams) (Jwt, error)
	CreateRefreshToken(ctx context.Context, params TokenCreateParams) (Jwt, error)
	CreateIdToken(ctx context.Context, params TokenCreateParams) (Jwt, error)
	CreateSessionToken(ctx context.Context, params TokenCreateParams) (Jwt, error)
	CreateSignedAccessToken(ctx context.Context, params TokenCreateParams) (*SignedJwt, error)
	CreateSignedRefreshToken(ctx context.Context, params TokenCreateParams) (*SignedJwt, error)
	CreateSignedIdToken(ctx context.Context, params TokenCreateParams) (*SignedJwt, error)
	CreateSignedSessionToken(ctx context.Context, params TokenCreateParams) (*SignedJwt, error)
}

func NewJwtService

func NewJwtService(keys JwkRepository) JwtService

type JwtSigningService

type JwtSigningService interface {
	Sign(ctx context.Context, token Jwt) (*SignedJwt, error)
	Create(ctx context.Context, claims Claims) (Jwt, error)
}

func NewJwtSigningService

func NewJwtSigningService(repo JwkRepository) JwtSigningService

type KeysFacade

type KeysFacade interface {
	ListJwks(ctx context.Context) ([]Jwk, error)
	GenerateNewJwk(ctx context.Context) error
	GetLatest(ctx context.Context) (Jwk, error)
}

func NewKeysFacade

func NewKeysFacade(jwkService JwkService) KeysFacade

type Repositories

type Repositories struct {
	Jwk JwkRepository
}

type Services

type Services struct {
	Jwk JwkService
	Jwt JwtService
}

type SignedJwt

type SignedJwt struct {
	Signature string
	// contains filtered or unexported fields
}

func (*SignedJwt) AppId

func (j *SignedJwt) AppId() string

func (*SignedJwt) Audience

func (j *SignedJwt) Audience() string

func (*SignedJwt) Claims

func (j *SignedJwt) Claims() map[string]interface{}

func (*SignedJwt) ClientId

func (j *SignedJwt) ClientId() string

func (*SignedJwt) ExpiresAt

func (j *SignedJwt) ExpiresAt() time.Time

func (*SignedJwt) ID

func (j *SignedJwt) ID() string

func (*SignedJwt) IssuedAt

func (j *SignedJwt) IssuedAt() time.Time

func (*SignedJwt) Issuer

func (j *SignedJwt) Issuer() string

func (*SignedJwt) Jti

func (j *SignedJwt) Jti() JtiParts

func (*SignedJwt) JwkID

func (j *SignedJwt) JwkID() string

func (*SignedJwt) Raw

func (j *SignedJwt) Raw() string

func (*SignedJwt) RawHeader

func (j *SignedJwt) RawHeader() map[string]interface{}

func (*SignedJwt) Scopes

func (j *SignedJwt) Scopes() shared.Scopes

func (*SignedJwt) Subject

func (j *SignedJwt) Subject() string

func (*SignedJwt) UserId

func (j *SignedJwt) UserId() string

type TokenCreateParams

type TokenCreateParams struct {
	User          *users.User
	App           *apps.Application
	Scopes        []string
	CorrelationId string
}

Jump to

Keyboard shortcuts

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