jwt

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package jwt implements authentication interfaces using JWT.

Index

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 Encode

func Encode(c jwt.Claims, secret []byte) (string, error)

Encode encodes the jwt Claim to a JWT string.

func NewContext

func NewContext(ctx context.Context, claims Claims) context.Context

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 Parse

func Parse(t string, s []byte, c jwt.Claims) error

Parse and validate a JWT string.

func ParseFromMetadata

func ParseFromMetadata(ctx context.Context, secret []byte, c jwt.Claims) error

ParseFromMetadata fetches the JWT from the :authorization metadata located in the `Context`, validates the JWT and extracts the Claims.

func SubjectEquals

func SubjectEquals(ctx context.Context, s string) bool

SubjectEquals checks if the JWT subject is equal to the provided subject in `sub`.

func TokenString

func TokenString(ctx context.Context) string

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

func FromContext(ctx context.Context) (c Claims, ok bool)

FromContext fetches the claims attched to the ctx.

func (Claims) ContainScopes

func (c Claims) ContainScopes(scopes ...string) bool

ContainScopes checks if `scopes` are present within the Claim.Scope.

Jump to

Keyboard shortcuts

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