Documentation
¶
Index ¶
- func ClaimString(s string) jwt.ClaimStrings
- func HashID(h hash.Hash, val string) string
- func IsTokenExpiredError(err error) bool
- func SetActorInContext(ctx context2.Context, actor *Actor) context2.Context
- type Actor
- func (a *Actor) BoolAttr(key string) bool
- func (a *Actor) ContextWith(ctx context.Context) context.Context
- func (a *Actor) GetRole() string
- func (a *Actor) IsAdmin() bool
- func (a *Actor) IsNormalActor() bool
- func (a *Actor) IsSuperAdmin() bool
- func (a *Actor) SetBoolAttr(key string, val bool)
- func (a *Actor) SetRole(role string)
- func (a *Actor) SetSliceAttr(key string, val []string)
- func (a *Actor) SetStrAttr(key, val string)
- func (a *Actor) SliceAttr(key string) []string
- func (a *Actor) StrAttr(key string) string
- type AuthProxyClaims
- func (tc *AuthProxyClaims) AdminUsername() (string, error)
- func (tc *AuthProxyClaims) IsAdmin() bool
- func (tc *AuthProxyClaims) IsExpired(ctx context.Context) bool
- func (tc *AuthProxyClaims) IsNormalActor() bool
- func (tc *AuthProxyClaims) IsSuperAdmin() bool
- func (tc *AuthProxyClaims) String() string
- type ClaimsBuilder
- type KeySelector
- type ParserBuilder
- type Signer
- type TokenBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClaimString ¶
func ClaimString(s string) jwt.ClaimStrings
ClaimString converts a singular string into a claims string.
func IsTokenExpiredError ¶
Types ¶
type Actor ¶
type Actor struct { // set by service ID string `json:"id"` Admin bool `json:"admin,omitempty"` SuperAdmin bool `json:"super_admin,omitempty"` // set by client IP string `json:"ip,omitempty"` Email string `json:"email,omitempty"` Attributes map[string]interface{} `json:"attrs,omitempty"` Role string `json:"role,omitempty"` }
Actor is the information that identifies who is making a request. This can be a actor in the calling system, an admin from the calling system, a devops admin from the cli, etc.
func GetActorFromContext ¶
GetActorFromContext gets an actor from the context, or returns nil if one is not present
func MustGetActorFromContext ¶
MustGetActorFromContext always returns an actor, or panics if an actor is not present on the context.
func (*Actor) ContextWith ¶
ContextWith sets actor in the context
func (*Actor) IsNormalActor ¶
IsNormalActor indicates that an actor is not an admin or superadmin
func (*Actor) IsSuperAdmin ¶
IsSuperAdmin is a helper to wrap the SuperAdmin attribute
func (*Actor) SetBoolAttr ¶
SetBoolAttr sets boolean attribute
func (*Actor) SetSliceAttr ¶
SetSliceAttr sets slice attribute for given key
func (*Actor) SetStrAttr ¶
SetStrAttr sets string attribute
type AuthProxyClaims ¶
type AuthProxyClaims struct { jwt.RegisteredClaims // Actor is the entity taking the action. Specifying the full actor here (versus just the ID in the subject) // implies that the actor should be upserted into the system as specified versus only working against a previous // actor configured in the system. Actor *Actor `json:"actor,omitempty"` // SessionOnly implies this token is only valid within the context of an existing session. SessionOnly bool `json:"sess_only,omitempty"` // SelfSigned indicates this token is signed with the GlobalAESKey. This mean that that AuthProxy has signed // this token to itself for auth transfer between services, a token used in session, etc. SelfSigned bool `json:"self_signed,omitempty"` // Nonce is a one-time-use value. Adding a nonce to the JWT make it a one-time-use for auth purposes. If you use // a nonce, the JWT must also have an expiry so that tracking of the nonce values do not need to be kept forever. Nonce *uuid.UUID `json:"nonce,omitempty"` }
AuthProxyClaims is the struct that defines a JWT for the auth service. It contains information about the actor (user or system taking the action) as well as standard JWT information.
func (*AuthProxyClaims) AdminUsername ¶
func (tc *AuthProxyClaims) AdminUsername() (string, error)
AdminUsername retrieves the username of an admin actor. Admin actors must have their id and token subject formatted in the form admin/username. If token subject and actor id do not match, or they are not correctly formatted, this method will return an error.
func (*AuthProxyClaims) IsAdmin ¶
func (tc *AuthProxyClaims) IsAdmin() bool
IsAdmin checks if the actor represented by these claims is an admin
func (*AuthProxyClaims) IsExpired ¶
func (tc *AuthProxyClaims) IsExpired(ctx context.Context) bool
IsExpired returns true if claims expired
func (*AuthProxyClaims) IsNormalActor ¶
func (tc *AuthProxyClaims) IsNormalActor() bool
IsNormalActor checks if the actor represented by these claims is not an admin or superadmin
func (*AuthProxyClaims) IsSuperAdmin ¶
func (tc *AuthProxyClaims) IsSuperAdmin() bool
IsSuperAdmin checks if the actor represented by these claims is an admin
func (*AuthProxyClaims) String ¶
func (tc *AuthProxyClaims) String() string
type ClaimsBuilder ¶
type ClaimsBuilder interface { WithIssuer(issuer string) ClaimsBuilder WithAudience(audience string) ClaimsBuilder // Specifies the audience of the claims; normally a service id WithAudiences(audience []string) ClaimsBuilder // Specifies the service that is intended to consume the claims. Communicated as aud. WithServiceId(serviceId config.ServiceId) ClaimsBuilder WithServiceIds(serviceIds []config.ServiceId) ClaimsBuilder WithExpiration(expiration time.Time) ClaimsBuilder WithExpiresIn(expiresIn time.Duration) ClaimsBuilder WithExpiresInCtx(ctx context.Context, expiresIn time.Duration) ClaimsBuilder WithSuperAdmin() ClaimsBuilder WithAdmin() ClaimsBuilder WithSelfSigned() ClaimsBuilder WithActorEmail(email string) ClaimsBuilder WithActorId(id string) ClaimsBuilder WithActor(actor *Actor) ClaimsBuilder WithSessionOnly() ClaimsBuilder WithNonce() ClaimsBuilder BuildCtx(context.Context) (*AuthProxyClaims, error) Build() (*AuthProxyClaims, error) MustBuild() AuthProxyClaims MustBuildCtx(context.Context) AuthProxyClaims }
ClaimsBuilder is an object to build Jwts to properly construct claims as expected with the actor/subject etc properly constructed.
func NewClaimsBuilder ¶
func NewClaimsBuilder() ClaimsBuilder
type KeySelector ¶
type KeySelector func(ctx context.Context, unverified *AuthProxyClaims) (kd config.KeyData, isShared bool, err error)
KeySelector is a function that takes a claims object and loads a key dynamically used to verify the JWT. This selector can mean that different actors can be verified with different keys.
Parameters: * ctx: Context used to load the key data * unverified: The claims that have been loaded from the JWT that have not yet had their signature verified
Returns: * kd: the key data to use * isShared: if the key data is a shared (aka secret) key. If false, will assume public key. * err: An error from loading key data. If specified, other return values are ignored.
type ParserBuilder ¶
type ParserBuilder interface { // WithKeySelector specifies a key selector function to dynamically load a key based on the unverified, parsed // JWT. This is useful for cases where the key used can vary based on the token issued. WithKeySelector(KeySelector) ParserBuilder // WithConfigKey specifies the key to be used for parsing as a config value. Key can be either secret or public. WithConfigKey(ctx context.Context, cfgKey config.Key) ParserBuilder // WithPublicKeyPath specifies the public key as a file path. WithPublicKeyPath(string) ParserBuilder // WithPublicKeyString specifies the public key as an explicit string value. WithPublicKeyString(string) ParserBuilder // WithPublicKey sets the public key using the provided byte slice. WithPublicKey([]byte) ParserBuilder WithSharedKeyPath(string) ParserBuilder WithSharedKeyString(string) ParserBuilder WithSharedKey([]byte) ParserBuilder ParseCtx(context.Context, string) (*AuthProxyClaims, error) Parse(string) (*AuthProxyClaims, error) MustParseCtx(context.Context, string) AuthProxyClaims MustParse(string) AuthProxyClaims }
ParserBuilder is a builder that can parse a JWT
func NewJwtTokenParserBuilder ¶
func NewJwtTokenParserBuilder() ParserBuilder
type Signer ¶
type TokenBuilder ¶
type TokenBuilder interface { // WithClaims allows the claims to be specified explicitly instead of built progressively WithClaims(c *AuthProxyClaims) TokenBuilder WithIssuer(issuer string) TokenBuilder WithAudience(audience string) TokenBuilder // Specifies the audience of the claims; normally a service id WithServiceId(serviceId config.ServiceId) TokenBuilder // Specifies the service that is intended to consume the claims. Communicated as aud. WithServiceIds(serviceId []config.ServiceId) TokenBuilder WithExpiration(expiration time.Time) TokenBuilder WithExpiresIn(expiresIn time.Duration) TokenBuilder WithExpiresInCtx(ctx context.Context, expiresIn time.Duration) TokenBuilder WithSuperAdmin() TokenBuilder WithAdmin() TokenBuilder WithSelfSigned() TokenBuilder WithActorEmail(email string) TokenBuilder WithActorId(id string) TokenBuilder WithActor(actor *Actor) TokenBuilder WithSessionOnly() TokenBuilder WithNonce() TokenBuilder WithConfigKey(ctx context.Context, cfgKey config.Key) (TokenBuilder, error) WithSecretConfigKeyData(ctx context.Context, cfgKeyData config.KeyData) (TokenBuilder, error) WithPrivateKeyPath(string) TokenBuilder WithPrivateKeyString(string) TokenBuilder WithPrivateKey([]byte) TokenBuilder WithSecretKeyPath(string) TokenBuilder WithSecretKeyString(string) TokenBuilder WithSecretKey([]byte) TokenBuilder TokenCtx(context.Context) (string, error) Token() (string, error) MustTokenCtx(context.Context) string MustToken() string Signer() (Signer, error) SignerCtx(context.Context) (Signer, error) MustSigner() Signer MustSignerCtx(context.Context) Signer }
TokenBuilder extends from ClaimsBuilder to provide options to sign tokens
func NewJwtTokenBuilder ¶
func NewJwtTokenBuilder() TokenBuilder