authenticator

package
v0.0.0-...-81dc835 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthenticatorClaimOOBOTPEmail is a claim with string value for OOB OTP email channel.
	AuthenticatorClaimOOBOTPEmail string = "https://authgear.com/claims/oob_otp/email"
	// AuthenticatorClaimOOBOTPPhone is a claim with string value for OOB OTP phone channel.
	AuthenticatorClaimOOBOTPPhone string = "https://authgear.com/claims/oob_otp/phone"
)
View Source
const (
	// AuthenticatorClaimPasskeyCredentialID is a claim with a string value.
	// nolint: gosec
	AuthenticatorClaimPasskeyCredentialID string = "https://authgear.com/claims/passkey/credential_id"
)
View Source
const (
	// AuthenticatorClaimTOTPDisplayName is a claim with string value for TOTP display name.
	AuthenticatorClaimTOTPDisplayName string = "https://authgear.com/claims/totp/display_name"
)

Variables

View Source
var ErrAuthenticatorNotFound = errors.New("authenticator not found")
View Source
var KeepPrimaryAuthenticatorCanHaveMFA = FilterFunc(func(ai *Info) bool {
	return ai.CanHaveMFA()
})

Functions

func NewErrDuplicatedAuthenticator

func NewErrDuplicatedAuthenticator(typ model.AuthenticatorType) error

Types

type Filter

type Filter interface {
	Keep(ai *Info) bool
}

func KeepKind

func KeepKind(kind Kind) Filter

func KeepPrimaryAuthenticatorOfIdentity

func KeepPrimaryAuthenticatorOfIdentity(ii *identity.Info) Filter

func KeepType

func KeepType(types ...model.AuthenticatorType) Filter

type FilterFunc

type FilterFunc func(ai *Info) bool
var KeepDefault FilterFunc = func(ai *Info) bool {
	return ai.IsDefault
}

func (FilterFunc) Keep

func (f FilterFunc) Keep(ai *Info) bool

type Info

type Info struct {
	ID        string                  `json:"id"`
	UserID    string                  `json:"user_id"`
	CreatedAt time.Time               `json:"created_at"`
	UpdatedAt time.Time               `json:"updated_at"`
	Type      model.AuthenticatorType `json:"type"`
	IsDefault bool                    `json:"is_default"`
	Kind      Kind                    `json:"kind"`

	Password *Password `json:"password,omitempty"`
	Passkey  *Passkey  `json:"passkey,omitempty"`
	TOTP     *TOTP     `json:"totp,omitempty"`
	OOBOTP   *OOBOTP   `json:"oobotp,omitempty"`
}

func ApplyFilters

func ApplyFilters(ais []*Info, filters ...Filter) (out []*Info)

func (*Info) AMR

func (i *Info) AMR() []string

func (*Info) CanHaveMFA

func (i *Info) CanHaveMFA() bool

func (*Info) Equal

func (i *Info) Equal(that *Info) bool

func (*Info) GetMeta

func (i *Info) GetMeta() model.Meta

func (*Info) IsApplicableTo

func (i *Info) IsApplicableTo(iden *identity.Info) bool

func (*Info) IsDependentOf

func (i *Info) IsDependentOf(iden *identity.Info) bool

func (*Info) IsIndependent

func (i *Info) IsIndependent() bool

func (*Info) StandardClaims

func (i *Info) StandardClaims() map[model.ClaimName]string

func (*Info) ToModel

func (i *Info) ToModel() model.Authenticator

func (*Info) ToPublicClaims

func (i *Info) ToPublicClaims() map[string]interface{}

func (*Info) ToRef

func (i *Info) ToRef() *Ref

func (*Info) UpdateUserID

func (i *Info) UpdateUserID(newUserID string) *Info

type Kind

type Kind = model.AuthenticatorKind
const (
	KindPrimary   Kind = model.AuthenticatorKindPrimary
	KindSecondary Kind = model.AuthenticatorKindSecondary
)

type MigrateSpec

type MigrateSpec struct {
	Type model.AuthenticatorType `json:"type,omitempty"`

	OOBOTP *OOBOTPMigrateSpec `json:"oobotp,omitempty"`
}

func (*MigrateSpec) GetSpec

func (s *MigrateSpec) GetSpec() *Spec

type OOBOTP

type OOBOTP struct {
	ID                   string                  `json:"id"`
	UserID               string                  `json:"user_id"`
	CreatedAt            time.Time               `json:"created_at"`
	UpdatedAt            time.Time               `json:"updated_at"`
	Kind                 string                  `json:"kind"`
	IsDefault            bool                    `json:"is_default"`
	OOBAuthenticatorType model.AuthenticatorType `json:"oob_authenticator_type"`
	Phone                string                  `json:"phone,omitempty"`
	Email                string                  `json:"email,omitempty"`
}

func (*OOBOTP) ToClaimPair

func (a *OOBOTP) ToClaimPair() (claimName model.ClaimName, claimValue string)

func (*OOBOTP) ToInfo

func (a *OOBOTP) ToInfo() *Info

func (*OOBOTP) ToTarget

func (a *OOBOTP) ToTarget() string

type OOBOTPMigrateSpec

type OOBOTPMigrateSpec struct {
	Email string `json:"email,omitempty"`
	Phone string `json:"phone,omitempty"`
}

type OOBOTPSpec

type OOBOTPSpec struct {
	Email string `json:"email,omitempty"`
	Phone string `json:"phone,omitempty"`
	Code  string `json:"code,omitempty"`
}

type Passkey

type Passkey struct {
	ID                  string                         `json:"id"`
	UserID              string                         `json:"user_id"`
	CreatedAt           time.Time                      `json:"created_at"`
	UpdatedAt           time.Time                      `json:"updated_at"`
	Kind                string                         `json:"kind"`
	IsDefault           bool                           `json:"is_default"`
	CredentialID        string                         `json:"credential_id"`
	CreationOptions     *model.WebAuthnCreationOptions `json:"creation_options,omitempty"`
	AttestationResponse []byte                         `json:"attestation_response,omitempty"`
	// SignCount of 0 means sign count is not supported by the authenticator.
	// So we do not include omitempty here.
	SignCount int64 `json:"sign_count"`
}

func (*Passkey) ToInfo

func (a *Passkey) ToInfo() *Info

type PasskeySpec

type PasskeySpec struct {
	AttestationResponse []byte `json:"attestation_response,omitempty"`
	AssertionResponse   []byte `json:"assertion_response,omitempty"`
}

type Password

type Password struct {
	ID           string     `json:"id"`
	UserID       string     `json:"user_id"`
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
	Kind         string     `json:"kind"`
	IsDefault    bool       `json:"is_default"`
	PasswordHash []byte     `json:"password_hash,omitempty"`
	ExpireAfter  *time.Time `json:"expire_after,omitempty"`
}

func (*Password) ToInfo

func (a *Password) ToInfo() *Info

type PasswordSpec

type PasswordSpec struct {
	PlainPassword string     `json:"-"`
	PasswordHash  string     `json:"-"`
	ExpireAfter   *time.Time `json:"-"`
}

type Ref

type Ref struct {
	model.Meta
	UserID string
	Type   model.AuthenticatorType
}

func (*Ref) ToRef

func (r *Ref) ToRef() *Ref

type Spec

type Spec struct {
	UserID    string                  `json:"user_id,omitempty"`
	Type      model.AuthenticatorType `json:"type,omitempty"`
	IsDefault bool                    `json:"is_default,omitempty"`
	Kind      Kind                    `json:"kind,omitempty"`

	Password *PasswordSpec `json:"password,omitempty"`
	Passkey  *PasskeySpec  `json:"passkey,omitempty"`
	TOTP     *TOTPSpec     `json:"totp,omitempty"`
	OOBOTP   *OOBOTPSpec   `json:"oobotp,omitempty"`
}

type TOTP

type TOTP struct {
	ID          string    `json:"id"`
	UserID      string    `json:"user_id"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	Kind        string    `json:"kind"`
	IsDefault   bool      `json:"is_default"`
	Secret      string    `json:"secret"`
	DisplayName string    `json:"display_name"`
}

func (*TOTP) ToInfo

func (a *TOTP) ToInfo() *Info

type TOTPSpec

type TOTPSpec struct {
	Code        string `json:"code,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
	Secret      string `json:"-"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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