auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Token   string `json:"access_token"`
	Type    string `json:"token_type"`
	Expires int64  `json:"expires_in"`
}

AccessToken represents an access token.

func (*AccessToken) Marshal

func (t *AccessToken) Marshal() string

Marshal marshals the AccessToken to a JSON string.

type Claims

type Claims struct {
	jwt.StandardClaims
	Username string              `json:"user"`
	Role     repository.UserRole `json:"role"`
}

Claims is the custom JWT claims container.

type JWTGenerator

type JWTGenerator struct {
	Keys          *Keys
	SigningMethod jwt.SigningMethod
}

JWTGenerator generates an AccessToken.

func NewJWTGenerator

func NewJWTGenerator(keys *Keys, signingMethod jwt.SigningMethod) *JWTGenerator

NewJWTGenerator returns a new instance of JWTGenerator.

func (*JWTGenerator) Generate

func (gen *JWTGenerator) Generate(username string, role repository.UserRole) (*AccessToken, error)

Generate generates an AccessToken using the username and role claims.

type JWTValidator

type JWTValidator struct {
	// contains filtered or unexported fields
}

JWTValidator validates and authorizes an AccessToken.

func NewJWTValidator

func NewJWTValidator(key *Keys, repo repository.Repository) *JWTValidator

NewJWTValidator returns a new instance of JWTValidator.

func (*JWTValidator) Authorize

func (val *JWTValidator) Authorize(token string, request *repository.RequestDetails) bool

Authorize validates the token and authorizes the actual request.

type Keys

type Keys struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
}

Keys represents a container for the private and public keys.

func NewKeys

func NewKeys() (*Keys, error)

NewKeys returns a new instance of Keys.

func NewKeysFromFile

func NewKeysFromFile(privateKeyPath string, publicKeyPath string) (*Keys, error)

NewKeysFromFile creates and returns a new instance of Keys from the files.

func NewKeysFromPem

func NewKeysFromPem(privatePem []byte, publicPem []byte) (*Keys, error)

NewKeysFromPem creates and returns a new instance of Keys from the pem byte arrays.

type TokenType

type TokenType int

TokenType represents a token type.

const (
	// BearerToken is an opaque string, not intended to have any meaning to clients using it.
	// Some servers will issue tokens that are a short `string` of hexadecimal characters,
	// while others may use structured tokens such as JSON Web Tokens.
	BearerToken TokenType = iota

	// BasicToken is a string where credentials is the base64 encoding of id and
	// password joined by a single colon :
	BasicToken
)

func (TokenType) ToString

func (t TokenType) ToString() string

ToString converts the TokenType to a string.

Jump to

Keyboard shortcuts

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