auth

package
v0.0.0-...-25770c3 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package auth provides authentication and authorization support. Authentication: You are who you say you are. Authorization: You have permission to do what you are requesting to do.

Index

Constants

View Source
const (
	RuleAuthenticate = "auth"
)

These the current set of rules we have for auth.

Variables

View Source
var ErrForbidden = errors.New("attempted action is not allowed")

ErrForbidden is returned when a auth issue is identified.

Functions

func IsAuthError

func IsAuthError(err error) bool

IsAuthError checks if an error of type AuthError exists.

func NewAuthError

func NewAuthError(format string, args ...any) error

NewAuthError creates an AuthError for the provided message.

Types

type Auth

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

Auth is used to authenticate clients. It can generate a token for a set of user claims and recreate the claims by parsing the token.

func New

func New(cfg Config) (*Auth, error)

New creates an Auth to support authentication/authorization.

func (*Auth) Authenticate

func (a *Auth) Authenticate(ctx context.Context, bearerToken string) (Claims, error)

Authenticate processes the token to validate the sender's token is valid.

func (*Auth) GenerateToken

func (a *Auth) GenerateToken(kid string, claims Claims) (string, error)

GenerateToken generates a signed JWT token string representing the user Claims.

type Claims

type Claims struct {
	jwt.RegisteredClaims
}

Claims represents the authorization claims transmitted via a JWT.

type Config

type Config struct {
	DB        *sqlx.DB
	KeyLookup KeyLookup
	Issuer    string
}

Config represents information required to initialize auth.

type KeyLookup

type KeyLookup interface {
	PrivateKey(kid string) (key string, err error)
	PublicKey(kid string) (key string, err error)
}

KeyLookup declares a method set of behavior for looking up private and public keys for JWT use. The return could be a PEM encoded string or a JWS based key.

Jump to

Keyboard shortcuts

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