ajwt

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: AGPL-3.0 Imports: 6 Imported by: 0

README

Access JWT Package

Access JWT Package can be used to process the internal bearer token set on the Authorization by our gateway.

This Authorization header contains an access token which have been transformed from opaque to a JWT contained authorization data.

This package helps developers to use this data to check routes and resources accesses.

Documentation

Index

Constants

View Source
const JWTStaticSignature = "wedontmindaboutsigningfornow"

JWTStaticSignature is the key used to sign JWT internally, we don't mind having a secret one for now since the jwt goes only inside our internal & private network

Variables

This section is empty.

Functions

func BuildPurposeScope

func BuildPurposeScope(label string) string

BuildPurposeScope takes a purpose label and return a purpose scope

func GetPurpose

func GetPurpose(scope string) string

GetPurpose takes a purpose scope and return the application purpose IDs contained inside Warning: GetPurpose is not meant to receive anything else than a purpose scope there is no error handling about getting an invalid purpose scope

func GetSignedToken

func GetSignedToken(ac *AccessClaims) (string, error)

GetSignedToken transforms an AccessClaims structure into a JWT

func IsAllowedScope

func IsAllowedScope(candidate string) bool

IsAllowedScope return true if given candidate string is considered as an allowed scope A scope can be: - openid scope - caller type scope: user|service|application - misadmin scope - role scope - purpose scope

func IsMisadminScope

func IsMisadminScope(candidate string) bool

IsMisadminScope return true if given scope string is considered as a misadmin scope.

func IsPurposeScope

func IsPurposeScope(candidate string) bool

IsPurposeScope return true if given candidate string is considered as a purpose scope.

func IsRoleScope

func IsRoleScope(candidate string) bool

IsRoleScope return true if given candidate string is considered as a role scope. Forbidden usage of * in role scopes.

func SetAccessClaimsJWT

func SetAccessClaimsJWT(ctx context.Context, jwt string) context.Context

SetAccessClaimsJWT override current in-context access claims JWT value

func SetAccesses

func SetAccesses(ctx context.Context, acc *AccessClaims) context.Context

SetAccesses returns ctx with AccessClaims set inside it using accessContextKey

func TrimPurposes

func TrimPurposes(scopes []string) []string

TrimPurposes removes application purpose scopes from given list of scopes and return it It does not modify scope directly but return scopes after the trim as a slice of strings

Types

type ACRSecLvl

type ACRSecLvl string

Security Level - Authentication Context Class Reference (a.k.a. ACR values) Corresponding to a level of certainty, while the token has been generated, of the identity of the token requester The higher the security level is, stronger is the possibility the subject claims correspond in reality to the person who generated an access token

var (
	ACRSecLvl1 ACRSecLvl = "1"
	ACRSecLvl2 ACRSecLvl = "2"
)

func (ACRSecLvl) String

func (s ACRSecLvl) String() string

type AccessClaims

type AccessClaims struct {
	Issuer    string   `json:"iss"` // Service which distributed the token
	Audiences []string `json:"aud"` // Audiences which should answer to the tooken
	ClientID  string   `json:"cli"` // SSO client ID which generated the token

	ExpiresAt int64 `json:"exp"` // Expiry time
	IssuedAt  int64 `json:"iat"` // Issuing time
	NotBefore int64 `json:"nbf"` // Time before use

	Subject string    `json:"sub"` // Subject (owner) bound to the token
	Scope   string    `json:"sco"` // Scope beared by the token
	ACR     ACRSecLvl `json:"acr"` // Authentication Class Reference

	Token      string      `json:"tok"` // Raw Access Token
	IdentityID string      `json:"mid"` // Misakey ID - Identity bound to the token
	AccountID  null.String `json:"aid"` // Account (nullable) bound to the token

	JWT string `json:"-"` // Raw JWT Token
}

Claims declared to format our Access JWTs Implement https://godoc.org/github.com/dgrijalva/jwt-go#Claims interface

func GetAccesses

func GetAccesses(ctx context.Context) *AccessClaims

GetAccesses returns AccessClaims found inside current context using defined accessContextKey It return a nil pointer if no claims have been found

func (*AccessClaims) ACRIsGTE

func (c *AccessClaims) ACRIsGTE(secLvl ACRSecLvl) error

ACRIsGTE compares AccessClaims ACR (Authentication Context Class - Sec Level) with the secLvl parameter It uses kind of >= operator principle and return an error if the current ACR is stricty inferior to asked one

func (*AccessClaims) GetAdminAppID

func (c *AccessClaims) GetAdminAppID() *string

GetAdminAppID return application on which the user is Admin on if not found, nil is returned

func (*AccessClaims) GetDPOAppID

func (c *AccessClaims) GetDPOAppID() *string

GetDPOAppID return application on which the user is DPO on if not found, nil is returned

func (*AccessClaims) IsAdminOn added in v1.7.0

func (c *AccessClaims) IsAdminOn(appID string) bool

func (*AccessClaims) IsAnyAdmin added in v1.3.0

func (c *AccessClaims) IsAnyAdmin() bool

func (*AccessClaims) IsAnyApp

func (c *AccessClaims) IsAnyApp() bool

IsAnyApp returns false if claims' scopes defines an application

func (*AccessClaims) IsAnyDPO added in v1.3.0

func (c *AccessClaims) IsAnyDPO() bool

func (*AccessClaims) IsAnyService

func (c *AccessClaims) IsAnyService() bool

IsAnyService returns true if claims' scopes defines a service

func (*AccessClaims) IsAnyUser

func (c *AccessClaims) IsAnyUser() bool

IsAnyUser returns true if claims' scopes defines a user

func (*AccessClaims) IsApp added in v1.7.0

func (c *AccessClaims) IsApp(appID string) bool

IsApp returns true if claims' scopes defines an application and its subject match given app ID

func (*AccessClaims) IsDPOOn added in v1.7.0

func (c *AccessClaims) IsDPOOn(appID string) bool

func (*AccessClaims) IsMisadmin added in v1.7.0

func (c *AccessClaims) IsMisadmin() bool

IsMisadmin returns true if claims' scopes defines a user & a misadmin

func (*AccessClaims) IsNotAdmin added in v1.3.0

func (c *AccessClaims) IsNotAdmin() bool

func (*AccessClaims) IsNotAdminOn

func (c *AccessClaims) IsNotAdminOn(appID string) bool

func (*AccessClaims) IsNotAnyApp

func (c *AccessClaims) IsNotAnyApp() bool

IsNotAnyApp returns false if claims' scopes defines an application

func (*AccessClaims) IsNotAnyService

func (c *AccessClaims) IsNotAnyService() bool

IsNotAnyService returns false if claims' scopes defines a service

func (*AccessClaims) IsNotAnyUser

func (c *AccessClaims) IsNotAnyUser() bool

IsAnyUser returns false if claims' scopes defines a user

func (*AccessClaims) IsNotApp

func (c *AccessClaims) IsNotApp(appID string) bool

IsNotApp returns false if claims' scopes defines an application and its subject match given app ID

func (*AccessClaims) IsNotDPO

func (c *AccessClaims) IsNotDPO() bool

func (*AccessClaims) IsNotDPOOn

func (c *AccessClaims) IsNotDPOOn(appID string) bool

func (*AccessClaims) IsNotMisadmin

func (c *AccessClaims) IsNotMisadmin() bool

IsNotMisadmin returns false if claims' scopes defines a user & a misadmin

func (*AccessClaims) IsNotService

func (c *AccessClaims) IsNotService(serviceID string) bool

IsNotService returns false if claims' scopes defines a service and its subject match given service ID

func (*AccessClaims) IsNotUser

func (c *AccessClaims) IsNotUser(userID string) bool

IsNotUser returns false if claims' scopes defines a user and its subject match given user ID

func (*AccessClaims) IsService added in v1.7.0

func (c *AccessClaims) IsService(serviceID string) bool

IsService returns true if claims' scopes defines a service and its subject match given service ID

func (*AccessClaims) IsUser added in v1.7.0

func (c *AccessClaims) IsUser(userID string) bool

IsUser returns true if claims' scopes defines a user and its subject match given user ID

func (*AccessClaims) SetRawJWT

func (c *AccessClaims) SetRawJWT(jwt string)

setRawJWT set the raw jwt corresponding to the access claims

func (*AccessClaims) Valid

func (c *AccessClaims) Valid() error

Valid : all required validation are today done on hydra side

func (*AccessClaims) ValidAudience

func (c *AccessClaims) ValidAudience(expected string) error

ValidAudience : check if the client is part of the audience

type AppRole

type AppRole struct {
	ApplicationID string
	RoleLabel     string
}

AppRole contains a role owned for a given application.

func GetRole

func GetRole(scope string) AppRole

GetRole takes a role scope and return the appID and the roleID contained inside Warning: GetRole is not meant to receive anything else than a role scope there is no error handling about getting an invalid role scope

Jump to

Keyboard shortcuts

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