Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
type FeedAuthEntity ¶
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 ¶
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