token

package
v0.0.0-...-4515e61 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2019 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMiddleware

func NewMiddleware(pK rsa.PublicKey) endpoint.MiddlewareFunc

NewMiddleware of token for a http request Moves a token from the authorization header to the context of a request

func ToContext

func ToContext(ctx context.Context, tok Token) context.Context

ToContext moves a token into a Context

Types

type ContextKey

type ContextKey string

ContextKey for context payload

const (
	//TokenContextKey for API-token in a context
	TokenContextKey ContextKey = "api_bearer_token"
)

type EventPayload

type EventPayload struct {
	*Info
}

EventPayload of a token in the event system of the API.

func EventPayloadFromContext

func EventPayloadFromContext(ctx context.Context) (*EventPayload, error)

EventPayloadFromContext returns a necessary event payload of token information from a given context.

type Info

type Info struct {
	User *User `json:"user"`
}

Info payload of a token

type Token

type Token interface {
	// Token returns the initial JWT-Token
	Token() *jwt.Token
	// String returns a signed and readable JWT-Token
	String(key *rsa.PrivateKey) (string, error)
	// Data of the token
	Data() *data
}

Token authenticates a consumer of the api

func Convert

func Convert(t *jwt.Token) (Token, error)

Convert a standard JWT-Token implementing necessary data to a Token interface.

func FromContext

func FromContext(ctx context.Context) (Token, error)

FromContext returns a Token from a Context

func New

func New(c *jwt.StandardClaims, user *User) Token

New creates a new api-friendly api token. More types can follow - e.g. specific API-Token in addition to user token.

func NewFromString

func NewFromString(pK *rsa.PublicKey, t string) (Token, error)

NewFromString parses a token object from a jwt token string

type User

type User struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

User represents an authenticated consumer of the api

func (*User) String

func (u *User) String() string

Jump to

Keyboard shortcuts

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