Documentation ¶
Overview ¶
Package jwt implements authentication interfaces using JWT.
Index ¶
- func Authenticator(secret []byte) auth.AuthenticatorFunc
- func Encode(c jwt.Claims, secret []byte) (string, error)
- func NewContext(ctx context.Context, claims Claims) context.Context
- func NewJWTCredentialsFromToken(token string) credentials.PerRPCCredentials
- func Parse(t string, s []byte, c jwt.Claims) error
- func ParseFromMetadata(ctx context.Context, secret []byte, c jwt.Claims) error
- func SubjectEquals(ctx context.Context, s string) bool
- func TokenString(ctx context.Context) string
- type Claims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authenticator ¶
func Authenticator(secret []byte) auth.AuthenticatorFunc
Authenticator returns an AuthenticatorFunc that validates the provided JWT token in the :authorization header of the metadata.
func NewContext ¶
NewContext creates a new context with the claims attached.
func NewJWTCredentialsFromToken ¶
func NewJWTCredentialsFromToken(token string) credentials.PerRPCCredentials
NewJWTCredentialsFromToken returns a grpc rpc credential using the provided JWT token. Does not validate the Token.
func ParseFromMetadata ¶
ParseFromMetadata fetches the JWT from the :authorization metadata located in the `Context`, validates the JWT and extracts the Claims.
func SubjectEquals ¶
SubjectEquals checks if the JWT subject is equal to the provided subject in `sub`.
func TokenString ¶
TokenString extracts the JWT toke as a string from `ctx`.
Types ¶
type Claims ¶
type Claims struct { Scope string `json:"scope,omitempty"` UserID string `json:"user_id,omitempty"` ClientID string `json:"client_id,omitempty"` TokenType string `json:"token_type,omitempty"` AvatarURL string `json:"avatar_url"` FullName string `json:"full_name"` // Once we have service-accounts in place, this should be removed. // Its up to each service to decide how they would like to handle // admin-callers. Admin bool `json:"admin,omitempty"` jwt.StandardClaims }
Claims represents the claims provided by the JWT.
func FromContext ¶
FromContext fetches the claims attched to the ctx.
func (Claims) ContainScopes ¶
ContainScopes checks if `scopes` are present within the Claim.Scope.