Documentation
¶
Overview ¶
Package authenticator provides functionalities to manage and generate one-time passwords.
Index ¶
- Variables
- func CreateNamespace(id, name string) error
- func DeleteAccount(namespace string, account string) error
- func DeleteNamespace(id string) error
- func EncodeTOTPQRCode(w io.Writer, account Account, format string, width, height int, ...) error
- func GenerateTOTP(ctx context.Context, namespace, account string, opts ...GenerateTOTPOption) (otp.OTP, error)
- func GenerateTOTPQRCode(path string, account Account, width, height int, ...) error
- func GetAllNamespaceIDs() ([]string, error)
- func SetAccount(namespace string, account Account) error
- func SetAccountStorage(s secretstorage.Storage[Account]) func()
- func SetNamespaceStorage(s secretstorage.Storage[Namespace]) func()
- func TOTPSecretFromEnv() otp.TOTPSecretProvider
- func UpdateNamespace(id string, n Namespace) error
- type Account
- type GenerateTOTPOption
- type Namespace
- type Option
- type TOTPSecretProvider
- type TOTPSecretProviderOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNamespaceExists indicates that the namespace already exists. ErrNamespaceExists = errors.New("namespace already exists") // ErrNamespaceNotFound indicates that the namespace was not found. ErrNamespaceNotFound = errors.New("namespace not found") )
var ( // ErrUnknownFormat indicates that the format is unknown. ErrUnknownFormat = fmt.Errorf("unknown format") // ErrUnsupportedFormat indicates that the format is unsupported. ErrUnsupportedFormat = fmt.Errorf("unsupported format") )
var ErrAccountNotFound = errors.New("account not found")
ErrAccountNotFound indicates that the account was not found.
Functions ¶
func CreateNamespace ¶
CreateNamespace creates a new namespace.
func DeleteAccount ¶ added in v0.2.0
DeleteAccount deletes the account and removes it from the namespace.
func EncodeTOTPQRCode ¶ added in v0.2.0
func EncodeTOTPQRCode(w io.Writer, account Account, format string, width, height int, listOfHints ...map[gozxing.EncodeHintType]any) error
EncodeTOTPQRCode produces a TOTP QR code for the given account.
func GenerateTOTP ¶
func GenerateTOTP(ctx context.Context, namespace, account string, opts ...GenerateTOTPOption) (otp.OTP, error)
GenerateTOTP generates a TOTP code for the given account.
func GenerateTOTPQRCode ¶ added in v0.2.0
func GenerateTOTPQRCode(path string, account Account, width, height int, listOfHints ...map[gozxing.EncodeHintType]any) error
GenerateTOTPQRCode generates a TOTP QR code for the given account.
func GetAllNamespaceIDs ¶
GetAllNamespaceIDs returns all namespace ids.
func SetAccount ¶ added in v0.2.0
SetAccount persists the account.
func SetAccountStorage ¶ added in v0.2.0
func SetAccountStorage(s secretstorage.Storage[Account]) func()
SetAccountStorage sets the account storage.
func SetNamespaceStorage ¶
func SetNamespaceStorage(s secretstorage.Storage[Namespace]) func()
SetNamespaceStorage sets the namespace storage.
func TOTPSecretFromEnv ¶ added in v0.3.0
func TOTPSecretFromEnv() otp.TOTPSecretProvider
TOTPSecretFromEnv returns a TOTP secret from the environment.
func UpdateNamespace ¶
UpdateNamespace updates the namespace.
Types ¶
type Account ¶ added in v0.2.0
type Account struct { Name string `json:"name" toml:"name" yaml:"name"` TOTPSecret otp.TOTPSecret `json:"totp_secret" toml:"totp_secret" yaml:"totp_secret"` Issuer string `json:"issuer" toml:"issuer" yaml:"issuer"` Metadata map[string]any `json:"metadata" toml:"metadata" yaml:"metadata"` }
Account represents an account.
func DecodeTOTPQRCode ¶ added in v0.2.0
DecodeTOTPQRCode decodes a TOTP QR code from the given file path.
func GetAccount ¶ added in v0.2.0
GetAccount returns the account.
func ParseTOTPQRCode ¶
ParseTOTPQRCode decodes a TOTP QR code from the given file path.
func (Account) MarshalText ¶ added in v0.2.0
MarshalText implements the encoding.TextMarshaler interface.
func (*Account) UnmarshalText ¶ added in v0.2.0
UnmarshalText implements the encoding.TextUnmarshaler interface.
type GenerateTOTPOption ¶
type GenerateTOTPOption interface {
// contains filtered or unexported methods
}
GenerateTOTPOption is an option to configure generateTOTPConfig.
func WithClock ¶
func WithClock(clock clock.Clock) GenerateTOTPOption
WithClock sets the clock to use.
func WithTOTPSecret ¶
func WithTOTPSecret(s otp.TOTPSecret) GenerateTOTPOption
WithTOTPSecret sets the secret to use.
func WithTOTPSecretGetter ¶
func WithTOTPSecretGetter(secretGetter otp.TOTPSecretGetter) GenerateTOTPOption
WithTOTPSecretGetter sets the secret getter to use.
type Namespace ¶
type Namespace struct { Name string `json:"name" toml:"name" yaml:"name"` Accounts []string `json:"accounts" toml:"accounts" yaml:"accounts"` }
Namespace represents a namespace.
func GetNamespace ¶
GetNamespace returns the namespace.
func (Namespace) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Namespace) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Option ¶ added in v0.3.0
type Option interface { GenerateTOTPOption TOTPSecretProviderOption }
Option is a configuration option for services provided by this package.
func WithLogger ¶ added in v0.2.0
WithLogger sets the logger to use.
type TOTPSecretProvider ¶ added in v0.5.0
type TOTPSecretProvider struct {
// contains filtered or unexported fields
}
TOTPSecretProvider manages the TOTP secret.
func TOTPSecretFromAccount ¶ added in v0.3.0
func TOTPSecretFromAccount(namespace, account string, opts ...TOTPSecretProviderOption) *TOTPSecretProvider
TOTPSecretFromAccount returns a TOTP secret getter for the given account.
func (*TOTPSecretProvider) DeleteTOTPSecret ¶ added in v0.5.0
func (s *TOTPSecretProvider) DeleteTOTPSecret(context.Context) error
DeleteTOTPSecret deletes the TOTP secret from the keyring.
func (*TOTPSecretProvider) SetTOTPSecret ¶ added in v0.5.0
func (s *TOTPSecretProvider) SetTOTPSecret(_ context.Context, secret otp.TOTPSecret, issuer string) error
SetTOTPSecret sets the TOTP secret to the keyring.
func (*TOTPSecretProvider) TOTPSecret ¶ added in v0.5.0
func (s *TOTPSecretProvider) TOTPSecret(ctx context.Context) otp.TOTPSecret
TOTPSecret returns the TOTP secret from the keyring.
type TOTPSecretProviderOption ¶ added in v0.5.0
type TOTPSecretProviderOption interface {
// contains filtered or unexported methods
}
TOTPSecretProviderOption is an option to configure TOTPSecretProvider.