auth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 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, error)

Marshal marshals the AccessToken to a JSON string.

type Claims

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

Claims is the custom JWT claims container.

type JWTGenerator

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

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(keys *Keys, backend repository.Repository) *JWTValidator

NewJWTValidator returns a new JWTValidator.

func (*JWTValidator) Authorize

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

Authorize validates the token and authorizes the actual request.

type Keys

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

Keys represents a container for the private and public keys.

func NewKeys

func NewKeys(config *config.Secret) (*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 containing the secrets information.

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) String

func (t TokenType) String() string

String returns the string representation of the TokenType.

Jump to

Keyboard shortcuts

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