auth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package auth is an auth util to decode and validate JWT tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth interface {
	// AuthMiddleware is the auth function for the auth interceptor
	AuthMiddleware() authmiddleware.AuthFunc

	// GetToken is a function to get the token from the context
	GetToken(ctx context.Context) *Claims
	// StoreToken is a function to store the token in the context
	StoreToken(ctx context.Context, claims *Claims) context.Context

	// ValidatePermissions is a function to validate the permissions
	ValidatePermissions(ctx context.Context, permissions []string) error
}

Auth is an interface for the auth middleware

func NewAuth

func NewAuth(opts ...Opt) Auth

NewAuth creates a new auth middleware

type Claims

type Claims struct {
	validator.RegisteredClaims
	CustomClaims
}

Claims is a struct to hold the claims

type CustomClaims

type CustomClaims struct {
	Permissions []string `json:"permissions"`
	Scope       string   `json:"scope"`
}

CustomClaims is a list of custom claims for the JWT token

func (*CustomClaims) Validate

func (c *CustomClaims) Validate(_ context.Context) error

Validate is a method to validate the custom claims

type Opt

type Opt func(*auth)

Opt is a function to set options for the auth middleware

func WithESPv2

func WithESPv2() Opt

WithESPv2 sets the ESPv2 mode for the auth middleware

func WithLogger

func WithLogger(logger *zap.Logger) Opt

WithLogger sets the logger for the auth middleware

func WithOIDC

func WithOIDC(iss, aud string) Opt

WithOIDC sets the OIDC issuer and audience for the auth middleware

Jump to

Keyboard shortcuts

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