token

package
Version: v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAccessObjects

func DecodeAccessObjects(value string) (ret []*authProto.AccessObject)

DecodeAccessObjects decodes resource access object from database record

func EncodeAccessObjects

func EncodeAccessObjects(req []*authProto.AccessObject) string

EncodeAccessObjects encodes resource access objects to store in database

func RequestToRecord

func RequestToRecord(req *authProto.CreateTokenRequest, token *IssuedToken) *authProto.StoredToken

RequestToRecord prepares a value to store in database

Types

type ExtensionFields

type ExtensionFields struct {
	UserIDHash  string `json:"user_id,omitempty"`
	Role        string `json:"role,omitempty"`
	PartTokenID string `json:"part_token_id,omitempty"`
}

ExtensionFields is an advanced fields included to JWT

type IssuedToken

type IssuedToken struct {
	Value    string
	ID       string
	IssuedAt time.Time
	LifeTime time.Duration
}

IssuedToken describes a token

type Issuer

type Issuer interface {
	IssueTokens(extensionFields ExtensionFields) (accessToken, refreshToken *IssuedToken, err error)
}

Issuer is interface for creating access and refresh tokens.

type IssuerValidator

type IssuerValidator interface {
	Issuer
	Validator
	AccessFromRefresh(refreshToken string) (accessToken *IssuedToken, err error)
	Now() time.Time
}

IssuerValidator is an interface for token factory

func NewJWTIssuerValidator

func NewJWTIssuerValidator(config JWTIssuerValidatorConfig) IssuerValidator

NewJWTIssuerValidator sets up validator for self-contained JSON Web Tokens

func NewMockIssuerValidator

func NewMockIssuerValidator(returnedLifeTime time.Duration) IssuerValidator

NewMockIssuerValidator sets up a mock object used for testing purposes

type JWTIssuerValidatorConfig

type JWTIssuerValidatorConfig struct {
	SigningMethod        jwt.SigningMethod
	Issuer               string
	AccessTokenLifeTime  time.Duration
	RefreshTokenLifeTime time.Duration
	SigningKey           interface{}
	ValidationKey        interface{}
}

JWTIssuerValidatorConfig is config for JSON Web Tokens issuer and validator

type Kind

type Kind int

Kind is a token kind (see OAuth 2 standards). According to standard it can be only KindAccess and KindRefresh.

const (
	// KindAccess represents access token
	KindAccess Kind = iota

	// KindRefresh represents refresh token
	KindRefresh
)

type ValidationResult

type ValidationResult struct {
	Valid bool
	ID    string
	Kind  Kind
}

ValidationResult describes token validation result.

type Validator

type Validator interface {
	ValidateToken(token string) (result *ValidationResult, err error)
}

Validator is interface for validating tokens

Jump to

Keyboard shortcuts

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