auth

package
v1.1.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeUser       = "b3scale"
	ScopeAdmin      = "b3scale:admin"
	ScopeNode       = "b3scale:node"
	ScopeRecordings = "b3scale:recordings"
)

Scopes

Variables

This section is empty.

Functions

func EncodeResource

func EncodeResource(hint, id string) string

EncodeResource associates an ID string with a type hint. Resources can for example be `recordings`, `frontend`, etc...

func ErrScopeRequired

func ErrScopeRequired(scopes ...string) *echo.HTTPError

ErrScopeRequired will be returned when a scope is missing from the response.

func GenerateNonce

func GenerateNonce(n int) string

GenerateNonce will create a random string of length n

func GenerateRef

func GenerateRef(n int) string

GenerateRef will create a most likely unique combination of words.

func MustDecodeResource

func MustDecodeResource(resource string) (string, string)

MustDecodeResource decodes splits a resource token into a type hint and an ID string. If the token is invalid, this function will panic.

func NewJWTAuthMiddleware

func NewJWTAuthMiddleware() echo.MiddlewareFunc

NewJWTAuthMiddleware creates a new instance of the echojwt middleware. Parameters like shared secrets, public keys, etc.. are retrieved from the environment.

Types

type Claims

type Claims struct {
	Scope string `json:"scope"`
	jwt.RegisteredClaims
}

Claims extends the JWT standard claims with a well-known `scope` claim.

func NewClaims

func NewClaims(sub string) *Claims

NewClaims creates a new set of claims for use with the API. This includes an ID and the subject.

The subject can be any string, however it will be used as an identifier for the 'user' making the request.

func ParseAPIToken

func ParseAPIToken(data string, secret string) (*Claims, error)

ParseAPIToken validates and parses a JWT token.

func (*Claims) Scopes

func (c *Claims) Scopes() []string

Scopes returns the list of scopes.

func (*Claims) Sign

func (c *Claims) Sign(secret string) (string, error)

Sign will create a new JWT from the claims.

func (*Claims) WithAudience

func (c *Claims) WithAudience(aud string) *Claims

WithAudience adds an audience to the claims.

func (*Claims) WithLifetime

func (c *Claims) WithLifetime(ttl time.Duration) *Claims

WithLifetime adds a lifetime to the claims.

func (*Claims) WithScopes

func (c *Claims) WithScopes(scopes ...string) *Claims

WithScopes adds a list of scopes to the claims.

func (*Claims) WithScopesCSV

func (c *Claims) WithScopesCSV(scopes string) *Claims

WithScopesCSV adds a list of scopes to the claims, separated by a delimiter.

type Scopes

type Scopes []string

Scopes is a list of scopes

Jump to

Keyboard shortcuts

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