authenticator

package
v1.0.0-beta.36 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PortalTokenIssuer = "openmeter"

Functions

func GetAuthenticatedSubject

func GetAuthenticatedSubject(ctx context.Context) string

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(portalTokenStrategy *PortalTokenStrategy) Authenticator

func (Authenticator) NewAuthenticatorMiddlewareFunc

func (a Authenticator) NewAuthenticatorMiddlewareFunc(swagger *openapi3.T) func(http.Handler) http.Handler

NewAuthenticatorMiddlewareFunc returns a middleware function that authenticates requests based on the OpenAPI 3 security requirements. TODO: support custom claims

type AuthenticatorContextKey

type AuthenticatorContextKey string
const (
	AuthenticatorSubjectSessionKey AuthenticatorContextKey = "openmeter_subject"
)

type PortalToken

type PortalToken struct {
	Id                *string    `json:"id"`
	AllowedMeterSlugs *[]string  `json:"allowedMeterSlugs,omitempty"`
	ExpiresAt         *time.Time `json:"expiresAt,omitempty"`
	Subject           string     `json:"subject"`
	Token             *string    `json:"token,omitempty"`
}

type PortalTokenClaims

type PortalTokenClaims struct {
	jwt.RegisteredClaims

	// Id is the unique identifier of the token.
	Id string `json:"id"`

	// AllowedMeterSlugs is a list of meter slugs that the token allows access to.
	AllowedMeterSlugs []string `json:"allowed_meter_slugs,omitempty"`
}

PortalTokenClaims is the claims struct for the portal token.

func (*PortalTokenClaims) GetAllowedMeterSlugs

func (c *PortalTokenClaims) GetAllowedMeterSlugs() ([]string, error)

GetAllowedMeterSlugs returns the list of allowed meter slugs.

type PortalTokenStrategy

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

func NewPortalTokenStrategy

func NewPortalTokenStrategy(secret string, expire time.Duration) (*PortalTokenStrategy, error)

func (*PortalTokenStrategy) Generate

func (t *PortalTokenStrategy) Generate(subject string, allowedMeterSlugs *[]string, expiresAt *time.Time) (*PortalToken, error)

func (*PortalTokenStrategy) Validate

func (t *PortalTokenStrategy) Validate(tokenString string) (*PortalTokenClaims, error)

Jump to

Keyboard shortcuts

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