auth

package
v0.0.0-...-a18969f Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	KeyCache     *lru.ARCCache
	KeyCacheTTL  time.Duration
	HTTPClient   *http.Client
	Limiter      *rate.Limiter
	ServiceDID   string
	PLCDirectory string
}

func NewAuth

func NewAuth(
	keyCacheSize int,
	keyCacheTTL time.Duration,
	plcDirectory string,
	requestsPerSecond int,
	serviceDID string,
) (*Auth, error)

NewAuth creates a new Auth instance with the given key cache size and TTL The PLC Directory URL is also required, as well as the DID of the service for JWT audience validation The key cache is used to cache the public keys of users for a given TTL The PLC Directory URL is used to fetch the public keys of users The service DID is used to validate the audience of JWTs The HTTP client is used to make requests to the PLC Directory A rate limiter is used to limit the number of requests to the PLC Directory

func (*Auth) AuthenticateGinRequestViaJWT

func (auth *Auth) AuthenticateGinRequestViaJWT(c *gin.Context)

func (*Auth) GetClaimsFromAuthHeader

func (auth *Auth) GetClaimsFromAuthHeader(ctx context.Context, authHeader string, claims jwt.Claims) error

func (*Auth) GetPLCEntry

func (auth *Auth) GetPLCEntry(ctx context.Context, did string) (*PLCEntry, error)

type KeyCacheEntry

type KeyCacheEntry struct {
	UserDID   string
	Key       *ecdsa.PublicKey
	ExpiresAt time.Time
}

type PLCEntry

type PLCEntry struct {
	Context            []string `json:"@context"`
	ID                 string   `json:"id"`
	AlsoKnownAs        []string `json:"alsoKnownAs"`
	VerificationMethod []struct {
		ID                 string `json:"id"`
		Type               string `json:"type"`
		Controller         string `json:"controller"`
		PublicKeyMultibase string `json:"publicKeyMultibase"`
	} `json:"verificationMethod"`
	Service []struct {
		ID              string `json:"id"`
		Type            string `json:"type"`
		ServiceEndpoint string `json:"serviceEndpoint"`
	} `json:"service"`
}

Jump to

Keyboard shortcuts

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