Documentation
¶
Overview ¶
Package apikey provides functions to generate and parse Seam-style API keys with base64 encoding.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyGenerator ¶
type APIKeyGenerator struct {
// contains filtered or unexported fields
}
func NewApiKeyGenerator ¶
func NewApiKeyGenerator(opts ApiKeyGeneratorOptions) (*APIKeyGenerator, error)
NewApiKeyGenerator creates a new APIKeyGenerator using options. Id generator and hasher are optional.
func (*APIKeyGenerator) CheckAPIKey ¶
func (a *APIKeyGenerator) CheckAPIKey(token, hash string) (bool, error)
CheckAPIKey verifies that the hash of the long token in the key matches the provided hash. At this point we expect the token to be in valid format e.g. extract via GetTokenComponents.
func (*APIKeyGenerator) GenerateAPIKey ¶
func (a *APIKeyGenerator) GenerateAPIKey(opts ...APIKeyOption) (*APIKey, error)
GenerateAPIKey generates a new API key using the generator's prefix.
func (*APIKeyGenerator) GetTokenComponents ¶
func (a *APIKeyGenerator) GetTokenComponents(token string) (*APIKey, error)
GetTokenComponents parses a full API key string into its components.
type APIKeyOption ¶
type APIKeyOption func(*apiKeyOptions)
func WithLongTokenData ¶
func WithLongTokenData(data any) APIKeyOption
func WithShortTokenData ¶
func WithShortTokenData(data any) APIKeyOption
type ApiKeyGeneratorOptions ¶
type ApiKeyGeneratorOptions struct {
TokenPrefix string
TokenSeparator rune // now a rune, not a string
TokenIdGenerator RandomBytesGenerator
TokenBytesGenerator RandomBytesGenerator
TokenHasher Hasher
ShortTokenBytes int
LongTokenBytes int
}
type Argon2IdHasher ¶
type Argon2IdHasher struct{}
Argon2IdHasher implements Hasher.
func (*Argon2IdHasher) Verify ¶
func (d *Argon2IdHasher) Verify(token, hash string) bool
type DefaultRandomBytesGenerator ¶
type DefaultRandomBytesGenerator struct{}
DefaultRandomBytesGenerator implements RandomIdGenerator using crypto/rand and base64.
type RandomBytesGenerator ¶
RandomBytesGenerator defines an interface for generating random IDs as a string.
type Sha256Hasher ¶
type Sha256Hasher struct{}
Sha256Hasher implements Hasher using SHA256.
func (*Sha256Hasher) Verify ¶
func (d *Sha256Hasher) Verify(token, hash string) bool