identity

package
v0.0.0-...-d9faf2a Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrVerificationCodeMismatch = errors.New("verification code mismatch")

Functions

This section is empty.

Types

type Authentication

type Authentication struct {
	ID        string                  `bson:"_id" json:"SessionToken"`
	Objective AuthenticationObjective `bson:"Objective" json:"Objective"`

	Completed bool `bson:"Completed" json:"Completed"`

	//> Filled if user is authenticated and going to add new identity/verifier (AuthenticationObjective)
	//  or if user completed one of the factors
	UserID string `bson:"UserID" json:"UserID"`

	RequiredFactorsCount int `bson:"RequiredFactorsCount" json:"RequiredFactorsCount"`

	Stages []*AuthenticationStage `bson:"Stages" json:"Stages"`

	CreationTime int64 `bson:"CreationTime" json:"CreationTime"`

	Version int `bson:"Version" json:"Version"`
}

type AuthenticationObjective

type AuthenticationObjective string
const (
	ObjectiveSignIn AuthenticationObjective = "sign_in"
	ObjectiveSignUp AuthenticationObjective = "sign_up"
	ObjectiveAttach AuthenticationObjective = "attach"
)

type AuthenticationStage

type AuthenticationStage struct {
	Completed bool `bson:"Completed" json:"Completed"`

	UserID string `bson:"UserID" json:"UserID"`

	VerifierName string `bson:"VerifierName" json:"VerifierName"`
	IdentityName string `bson:"IdentityName" json:"IdentityName"`
	Identity     string `bson:"Identity" json:"Identity"`

	StoredSecurityCode string `bson:"StoredSecurityCode" json:"StoredSecurityCode"`
	InputSecurityCode  string `bson:"InputSecurityCode" json:"InputSecurityCode"`

	OAuth2State string `bson:"OAuth2State" json:"OAuth2State"`

	VerifierData *VerifierData `bson:"VerifierData" json:"VerifierData"`
}

type B

type B map[string][]byte

type Backend

type Backend interface {
	GetAuthentication(ctx context.Context, id string) (*Authentication, error)
	CreateAuthentication(ctx context.Context, id string, objective AuthenticationObjective, userID string) (*Authentication, error)
	SaveAuthentication(ctx context.Context, auth *Authentication) (*Authentication, error)
	RemoveAuthentication(ctx context.Context, id string) error

	GetUser(ctx context.Context, id string) (*User, error)
	CreateUser(ctx context.Context, user *User) (*User, error)
	SaveUser(ctx context.Context, user *User) (*User, error)
	GetUserByIdentity(ctx context.Context, identityName, identity string) (*User, error)
}

type Identity

type Identity interface {
	Info() IdentityInfo
	NormalizeAndValidateIdentity(idn string) (idnNormalized string, err error)
}

type IdentityData

type IdentityData struct {
	Name     string `bson:"Name" json:"Name"`
	Identity string `bson:"Identity" json:"Identity"`
}

type IdentityInfo

type IdentityInfo struct {
	Name string
}

type IdentitySummary

type IdentitySummary struct {
	Name       string
	Standalone bool

	Identity Identity

	Verifiers []*VerifierSummary
}

type M

type M map[string]string

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func New

func New(backend Backend, identities []Identity, verifiers []Verifier) (*Manager, error)

func (*Manager) Session

func (mgr *Manager) Session(cookie cookie.Cookie) *Session

type OAuth2Verifier

type OAuth2Verifier interface {
	Verifier

	GetOAuth2URL(code string) string
	HandleOAuth2Callback(ctx context.Context, code string) (token *oauth2.Token, err error)
	GetOAuth2Identity(ctx context.Context, accessToken string) (identity *IdentityData, verifierData *VerifierData, err error)
}

type Options

type Options struct {
}

type RegularVerifier

type RegularVerifier interface {
	Verifier

	StartRegularVerification(ctx context.Context, identity string, verifierData VerifierData) (securityCode string, err error)
}

type ReverseVerifier

type ReverseVerifier interface {
	Verifier

	StartReverseVerification(ctx context.Context) (target, securityCode string, err error)
}

type Session

type Session struct {
	// contains filtered or unexported fields
}

func (*Session) CancelAuthentication

func (sess *Session) CancelAuthentication(ctx context.Context) error

func (*Session) CheckStatus

func (sess *Session) CheckStatus(ctx context.Context) (Status, error)

func (*Session) Info

func (sess *Session) Info() (sid, uid string)

func (*Session) ListMyIdentitiesAndVerifiers

func (sess *Session) ListMyIdentitiesAndVerifiers(ctx context.Context) (idn []IdentityData, ver []VerifierSummary, err error)

FIXME Why IdentityData??? Not summary???

func (*Session) ListSupportedIdentitiesAndVerifiers

func (sess *Session) ListSupportedIdentitiesAndVerifiers() (idn []IdentitySummary, ver []VerifierSummary, err error)

func (*Session) LoginAs

func (sess *Session) LoginAs(uid string) (sid string, err error)

func (*Session) Logout

func (sess *Session) Logout(ctx context.Context) (*Status, error)

func (*Session) Start

func (sess *Session) Start(ctx context.Context, verifierName string, args M, identityName, identity string) (M, error)

func (*Session) StartAuthentication

func (sess *Session) StartAuthentication(ctx context.Context, objective AuthenticationObjective) error

func (*Session) Verify

func (sess *Session) Verify(ctx context.Context, verifierName, verificationCode, identityName, identity string) error

type StaticVerifier

type StaticVerifier interface {
	Verifier

	InitStaticVerifier(ctx context.Context, verifierData *VerifierData, args M) (res M, err error)
	StaticVerify(ctx context.Context, verifierData VerifierData, inputCode string) (err error)
}

type Status

type Status struct {
	Token string

	Authenticating *StatusAuthenticating
	Authenticated  *StatusAuthenticated
}

type StatusAuthenticated

type StatusAuthenticated struct {
	User string
}

type StatusAuthenticating

type StatusAuthenticating struct {
	Objective        AuthenticationObjective
	RemainingFactors int
	CompletedFactors []StatusCompletedFactors
}

type StatusCompletedFactors

type StatusCompletedFactors struct {
	VerifierName string
	IdentityName string
	Identity     string
}

type User

type User struct {
	ID string `bson:"_id" json:"ID"`

	// TODO
	LastVerificationTime int64 `bson:"LastVerificationTime" json:"LastVerificationTime"`

	Identities        []IdentityData `bson:"Identities" json:"Identities"` // /name/identity/**
	Verifiers         []VerifierData `bson:"Verifiers" json:"Verifiers"`
	AuthFactorsNumber int            `bson:"AuthFactorsNumber" json:"AuthFactorsNumber"`

	Version int `bson:"Version" json:"Version"`
}

type Verifier

type Verifier interface {
	Info() VerifierInfo
}

type VerifierData

type VerifierData struct {
	Name               string `bson:"Name" json:"Name"`
	Identity           string `bson:"Identity" json:"Identity"`
	AuthenticationData B      `bson:"AuthenticationData" json:"AuthenticationData"` // /identity/value
	AdditionalData     B      `bson:"AdditionalData" json:"AdditionalData"`
}

type VerifierInfo

type VerifierInfo struct {
	Name         string
	IdentityName string
}

type VerifierSummary

type VerifierSummary struct {
	Name         string
	IdentityName string
	Standalone   bool

	Identity *IdentitySummary

	Verifier Verifier

	SupportRegular bool
	SupportReverse bool
	SupportOAuth2  bool
	SupportStatic  bool
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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