auth

package
v0.0.0-...-1eb5c16 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAPIKeyNotFound = fmt.Errorf("API key not found")

Functions

This section is empty.

Types

type APIKeyProvider

type APIKeyProvider interface {
	GetEntityFromAPIKey(ctx context.Context, apiKey string) (*FeedAuthEntity, error)
}

type Auth

type Auth struct {
	KeyCache    *lru.ARCCache[string, KeyCacheEntry]
	KeyCacheTTL time.Duration
	ServiceDID  string
	Dir         *identity.CacheDirectory
	// A bit of a hack for small-scope authenticated APIs
	KeyProvider APIKeyProvider
}

func NewAuth

func NewAuth(
	keyCacheSize int,
	keyCacheTTL time.Duration,
	requestsPerSecond int,
	serviceDID string,
	keyProvider APIKeyProvider,
) (*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) AuthenticateGinRequestViaAPIKey

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

AuthenticateGinRequestViaAPIKey authenticates a Gin request via an API key statically configured for the app, this is useful for testing and debugging or use-case specific scenarios where a DID is not available.

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

type FeedAuthEntity

type FeedAuthEntity struct {
	FeedAlias string `json:"feed_alias"`
	APIKey    string `json:"api_key"`
	UserDID   string `json:"user_did"`
}

type KeyCacheEntry

type KeyCacheEntry struct {
	UserDID   string
	Key       any
	ExpiresAt time.Time
}

type StaticProvider

type StaticProvider struct {
	APIKeyFeedMap map[string]*FeedAuthEntity
	// contains filtered or unexported fields
}

func NewStaticProvider

func NewStaticProvider() *StaticProvider

func (*StaticProvider) GetEntityFromAPIKey

func (p *StaticProvider) GetEntityFromAPIKey(ctx context.Context, apiKey string) (*FeedAuthEntity, error)

func (*StaticProvider) UpdateAPIKeyFeedMapping

func (p *StaticProvider) UpdateAPIKeyFeedMapping(ctx context.Context, apiKey string, feedAuthEntity *FeedAuthEntity)

type StoreProvider

type StoreProvider struct {
	Store *store.Store
}

func NewStoreProvider

func NewStoreProvider(s *store.Store) *StoreProvider

func (*StoreProvider) GetEntityFromAPIKey

func (p *StoreProvider) GetEntityFromAPIKey(ctx context.Context, apiKey string) (*FeedAuthEntity, error)

func (*StoreProvider) UpdateAPIKeyFeedMapping

func (p *StoreProvider) UpdateAPIKeyFeedMapping(ctx context.Context, apiKey string, feedAuthEntity *FeedAuthEntity) error

Jump to

Keyboard shortcuts

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