Documentation ¶
Index ¶
- Variables
- type Config
- type Service
- func (s *Service) Create(ctx context.Context, userID uuid.UUID, expiration time.Duration) (apiKey string, expiresAt time.Time, err error)
- func (s *Service) GenerateNewKey(ctx context.Context) (apiKey, hash string, err error)
- func (s *Service) GetUserAndExpirationFromKey(ctx context.Context, apiKey string) (userID uuid.UUID, exp time.Time, err error)
- func (s *Service) HashKey(ctx context.Context, apiKey string) (hash string, err error)
- func (s *Service) InsertIntoDB(ctx context.Context, oAuthToken oidc.OAuthToken, now time.Time, ...) (expiresAt time.Time, err error)
- func (s *Service) Revoke(ctx context.Context, apiKey string) (err error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Error describes internal rest keys error. Error = errs.Class("rest keys service") // ErrDuplicateKey is error type that occurs when a generated account // management api key already exists. ErrDuplicateKey = errs.Class("duplicate key") // ErrInvalidKey is an error type that occurs when a user submits a key // that does not match anything in the database. ErrInvalidKey = errs.Class("invalid key") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DefaultExpiration time.Duration `help:"expiration to use if user does not specify an rest key expiration" default:"720h"`
}
Config contains configuration parameters for rest keys.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles operations regarding rest keys.
func NewService ¶
func NewService(db oidc.OAuthTokens, config Config) *Service
NewService creates a new rest keys service.
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, userID uuid.UUID, expiration time.Duration) (apiKey string, expiresAt time.Time, err error)
Create creates and inserts an rest key into the db.
func (*Service) GenerateNewKey ¶
GenerateNewKey generates a new account management api key.
func (*Service) GetUserAndExpirationFromKey ¶
func (s *Service) GetUserAndExpirationFromKey(ctx context.Context, apiKey string) (userID uuid.UUID, exp time.Time, err error)
GetUserAndExpirationFromKey gets the userID and expiration date attached to an account management api key.
func (*Service) HashKey ¶
HashKey returns a hash of api key. This is used for hashing inside GetUserFromKey.
func (*Service) InsertIntoDB ¶
func (s *Service) InsertIntoDB(ctx context.Context, oAuthToken oidc.OAuthToken, now time.Time, expiration time.Duration) (expiresAt time.Time, err error)
InsertIntoDB checks OAuthTokens DB for a token before inserting. This is because OAuthTokens DB allows duplicate tokens, but we can't have duplicate api keys.
Click to show internal directories.
Click to hide internal directories.