identity

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 37 Imported by: 11

README

go-identity

Overview

This purpose is a library for the managing user identities for applications. The core of the library is User and Database data structures.

The User data structure captures the dynamics of user identities in the United States.

The Database data strcuture allows managing these identities. Currently, the Database provides a way of managing local users for a web application.

The key concurrency features of the Database are:

  • Only one Go routine is allowed making modifications to users at a time. During that time, the entire database locks.
  • Keeps user identities in Users slice of the Database data structure. The elements of the slice are pointers of User data structure The slice only grows in size.
  • Keeps references to user identities in a number hashes for faster lookup. The keys in the hashes are strings and the value is either a single pointer to User or a slice of pointers to User instances. If a reference keeps unique values, then it is a single pointer, e.g. username. Otherwise, e.g. in the case of being a part of a company, it is a slice.

The following keys are unique across the database:

  • ID
  • Username
  • EmailAddress: a user can have multiple emails, but the emails must be unique across the database.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreditCardAssociations = []*CreditCardAssociation{
	&CreditCardAssociation{
		Name:       "American Express",
		CodeName:   "CID",
		CodeFormat: "NNNN",
		Aliases: []string{
			"amex", "AMEX",
		},
	},
	&CreditCardAssociation{
		Name: "Diners Club",
		Aliases: []string{
			"diners",
		},
		CodeName:   "Security Code",
		CodeFormat: "NNN",
	},
	&CreditCardAssociation{
		Name: "Discover",
		Aliases: []string{
			"discover",
		},
		CodeName:   "CID",
		CodeFormat: "NNN",
	},
	&CreditCardAssociation{
		Name: "Mastercard",
		Aliases: []string{
			"mastercard",
		},
		CodeName:   "CVC2",
		CodeFormat: "NNN",
	},
	&CreditCardAssociation{
		Name: "Visa",
		Aliases: []string{
			"visa",
		},
		CodeName:   "CVC2",
		CodeFormat: "NNN",
	},
}

CreditCardAssociations is a collection of most popular credit card issuers.

View Source
var CreditCardIssuers = []*CreditCardIssuer{}

CreditCardIssuers is a collection of most popular credit card issuers.

Functions

func GetRandomString added in v1.0.13

func GetRandomString(i int) string

GetRandomString returns X character long random string.

func GetRandomStringFromRange added in v1.0.13

func GetRandomStringFromRange(a, b int) string

GetRandomStringFromRange generates random string of a random length. The random lenght is bounded by a and b.

func NewID

func NewID() string

NewID returns a random ID to be used for user identification.

func NewRandomString added in v1.0.6

func NewRandomString(length int) string

NewRandomString returns a random string.

Types

type APIKey added in v1.1.5

type APIKey struct {
	ID         string    `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Prefix     string    `json:"prefix,omitempty" xml:"prefix,omitempty" yaml:"prefix,omitempty"`
	Usage      string    `json:"usage,omitempty" xml:"usage,omitempty" yaml:"usage,omitempty"`
	Comment    string    `json:"comment,omitempty" xml:"comment,omitempty" yaml:"comment,omitempty"`
	Payload    string    `json:"payload,omitempty" xml:"payload,omitempty" yaml:"payload,omitempty"`
	Expired    bool      `json:"expired,omitempty" xml:"expired,omitempty" yaml:"expired,omitempty"`
	ExpiredAt  time.Time `json:"expired_at,omitempty" xml:"expired_at,omitempty" yaml:"expired_at,omitempty"`
	CreatedAt  time.Time `json:"created_at,omitempty" xml:"created_at,omitempty" yaml:"created_at,omitempty"`
	Disabled   bool      `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
	DisabledAt time.Time `json:"disabled_at,omitempty" xml:"disabled_at,omitempty" yaml:"disabled_at,omitempty"`
}

APIKey is an API key.

func NewAPIKey added in v1.1.5

func NewAPIKey(r *requests.Request) (*APIKey, error)

NewAPIKey returns an instance of APIKey.

func (*APIKey) Disable added in v1.1.5

func (p *APIKey) Disable()

Disable disables APIKey instance.

func (*APIKey) Match added in v1.1.6

func (p *APIKey) Match(s string) bool

Match returns true when the provided API matches.

type APIKeyBundle added in v1.1.5

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

APIKeyBundle is a collection of API keys.

func NewAPIKeyBundle added in v1.1.5

func NewAPIKeyBundle() *APIKeyBundle

NewAPIKeyBundle returns an instance of APIKeyBundle.

func (*APIKeyBundle) Add added in v1.1.5

func (b *APIKeyBundle) Add(k *APIKey)

Add adds APIKey to APIKeyBundle.

func (*APIKeyBundle) Get added in v1.1.5

func (b *APIKeyBundle) Get() []*APIKey

Get returns APIKey instances of the APIKeyBundle.

func (*APIKeyBundle) Size added in v1.1.5

func (b *APIKeyBundle) Size() int

Size returns the number of APIKey instances in APIKeyBundle.

type AttestationObject added in v1.0.20

type AttestationObject struct {
	AttestationStatement *AttestationStatement `json:"attStmt,omitempty" xml:"attStmt,omitempty" yaml:"attStmt,omitempty"`
	AuthData             *AuthData             `json:"authData,omitempty" xml:"authData,omitempty" yaml:"authData,omitempty"`
	Format               string                `json:"fmt,omitempty" xml:"fmt,omitempty" yaml:"fmt,omitempty"`
}

AttestationObject is Webauthn AttestationObject.

type AttestationStatement added in v1.0.20

type AttestationStatement struct {
	Algorithm int64  `json:"alg,omitempty" xml:"alg,omitempty" yaml:"alg,omitempty"`
	Signature string `json:"sig,omitempty" xml:"sig,omitempty" yaml:"sig,omitempty"`
	// The string in the first element of the slice contains the certificate associates
	// with the authenticaing device. The following commands allow the viewing of the
	// cerificate. The Subject contains the serial number associated with the device.
	// 1. `echo -n "base64 encoded value" | base64 -d > key.crt`
	// 2. `openssl x509 -in key.crt -inform der -text`
	Certificates []string `json:"x5c,omitempty" xml:"x5c,omitempty" yaml:"x5c,omitempty"`
}

AttestationStatement is AttestationStatement of the Webauthn AttestationObject.

type AuthData added in v1.0.20

type AuthData struct {
	RelyingPartyID   string          `json:"rpIdHash,omitempty" xml:"rpIdHash,omitempty" yaml:"rpIdHash,omitempty"`
	Flags            map[string]bool `json:"flags,omitempty" xml:"flags,omitempty" yaml:"flags,omitempty"`
	SignatureCounter uint32          `json:"signatureCounter,omitempty" xml:"signatureCounter,omitempty" yaml:"signatureCounter,omitempty"`
	Extensions       interface{}     `json:"extensions,omitempty" xml:"extensions,omitempty" yaml:"extensions,omitempty"`
	CredentialData   *CredentialData `json:"credentialData,omitempty" xml:"credentialData,omitempty" yaml:"credentialData,omitempty"`
}

AuthData is AuthData of the Webauthn AttestationObject.

type ClientData added in v1.0.20

type ClientData struct {
	Challenge   string `json:"challenge,omitempty" xml:"challenge,omitempty" yaml:"challenge,omitempty"`
	CrossOrigin bool   `json:"crossOrigin,omitempty" xml:"crossOrigin,omitempty" yaml:"crossOrigin,omitempty"`
	Origin      string `json:"origin,omitempty" xml:"origin,omitempty" yaml:"origin,omitempty"`
	Type        string `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
}

ClientData represents the contextual bindings of both the WebAuthn Relying Party and the client. It is a key-value mapping whose keys are strings. Values can be any type that has a valid encoding in JSON. Its structure is defined by the following Web IDL.

type CredentialData added in v1.0.20

type CredentialData struct {
	// The AAGUID of the authenticator.
	AAGUID string `json:"aaguid,omitempty" xml:"aaguid,omitempty" yaml:"aaguid,omitempty"`
	// A probabilistically-unique byte sequence identifying a public key credential source and its authentication assertions.
	CredentialID string `json:"credentialId,omitempty" xml:"credentialId,omitempty" yaml:"credentialId,omitempty"`
	// The credential public key encoded in COSE Key format
	PublicKey map[string]interface{} `json:"publicKey,omitempty" xml:"publicKey,omitempty" yaml:"publicKey,omitempty"`
}

CredentialData is attested credential data. It is a variable-length byte array added to the authenticator data when generating an attestation object for a given credential.

type CreditCard

type CreditCard struct {
	Number      string                 `json:"number,omitempty" xml:"number,omitempty" yaml:"number,omitempty"`
	Issuer      *CreditCardIssuer      `json:"issuer,omitempty" xml:"issuer,omitempty" yaml:"issuer,omitempty"`
	Association *CreditCardAssociation `json:"association,omitempty" xml:"association,omitempty" yaml:"association,omitempty"`
	Code        string                 `json:"code,omitempty" xml:"code,omitempty" yaml:"code,omitempty"`
	ExpiresAt   time.Time              `json:"expires_at,omitempty" xml:"expires_at,omitempty" yaml:"expires_at,omitempty"`
	IssuedAt    time.Time              `json:"issued_at,omitempty" xml:"issued_at,omitempty" yaml:"issued_at,omitempty"`
}

CreditCard represents a credit card.

func NewCreditCard

func NewCreditCard() *CreditCard

NewCreditCard returns an instance of CreditCard

func (*CreditCard) AddAssociation

func (cc *CreditCard) AddAssociation(s string) error

AddAssociation adds the name of the association, e.g. Visa, American Express, etc., to a credit card

func (*CreditCard) AddIssuer

func (cc *CreditCard) AddIssuer(s string) error

AddIssuer adds the name of the issuer, e.g. CitiGroup, CapitalOne, etc.

type CreditCardAssociation

type CreditCardAssociation struct {
	Name       string   `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Aliases    []string `json:"aliases,omitempty" xml:"aliases,omitempty" yaml:"aliases,omitempty"`
	CodeName   string   `json:"code_name,omitempty" xml:"code_name,omitempty" yaml:"code_name,omitempty"`
	CodeFormat string   `json:"code_format,omitempty" xml:"code_format,omitempty" yaml:"code_format,omitempty"`
}

CreditCardAssociation represents a credit card association, e.g. Visa, American Express, etc., to a credit card

func NewCreditCardAssociation

func NewCreditCardAssociation() *CreditCardAssociation

NewCreditCardAssociation returns an instance of

type CreditCardIssuer

type CreditCardIssuer struct {
	Name    string   `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Aliases []string `json:"aliases,omitempty" xml:"aliases,omitempty" yaml:"aliases,omitempty"`
}

CreditCardIssuer represents the issuer, e.g. Visa, American Express, etc.

func NewCreditCardIssuer

func NewCreditCardIssuer() *CreditCardIssuer

NewCreditCardIssuer returns an instance of

type Database

type Database struct {
	Version      string    `json:"version,omitempty" xml:"version,omitempty" yaml:"version,omitempty"`
	Policy       Policy    `json:"policy,omitempty" xml:"policy,omitempty" yaml:"policy,omitempty"`
	Revision     uint64    `json:"revision,omitempty" xml:"revision,omitempty" yaml:"revision,omitempty"`
	LastModified time.Time `json:"last_modified,omitempty" xml:"last_modified,omitempty" yaml:"last_modified,omitempty"`
	Users        []*User   `json:"users,omitempty" xml:"users,omitempty" yaml:"users,omitempty"`
	// contains filtered or unexported fields
}

Database is user identity database.

func NewDatabase

func NewDatabase(fp string) (*Database, error)

NewDatabase return an instance of Database.

func (*Database) AddAPIKey added in v1.1.5

func (db *Database) AddAPIKey(r *requests.Request) error

AddAPIKey adds API key for a user.

func (*Database) AddMfaToken added in v1.0.15

func (db *Database) AddMfaToken(r *requests.Request) error

AddMfaToken adds MFA token for a user.

func (*Database) AddPublicKey added in v1.0.12

func (db *Database) AddPublicKey(r *requests.Request) error

AddPublicKey adds public key, e.g. GPG or SSH, for a user.

func (*Database) AddUser

func (db *Database) AddUser(r *requests.Request) error

AddUser adds user identity to the database.

func (*Database) AuthenticateUser

func (db *Database) AuthenticateUser(r *requests.Request) error

AuthenticateUser adds user identity to the database.

func (*Database) ChangeUserPassword added in v1.0.6

func (db *Database) ChangeUserPassword(r *requests.Request) error

ChangeUserPassword change user password.

func (*Database) Copy added in v1.1.1

func (db *Database) Copy(fp string) error

Copy copies the database to another file.

func (*Database) DeleteAPIKey added in v1.1.5

func (db *Database) DeleteAPIKey(r *requests.Request) error

DeleteAPIKey deletes an API key associated with a user by key id.

func (*Database) DeleteMfaToken added in v1.0.15

func (db *Database) DeleteMfaToken(r *requests.Request) error

DeleteMfaToken deletes MFA token associated with a user by token id.

func (*Database) DeletePublicKey added in v1.0.14

func (db *Database) DeletePublicKey(r *requests.Request) error

DeletePublicKey deletes a public key associated with a user by key id.

func (*Database) DeleteUser added in v1.1.1

func (db *Database) DeleteUser(r *requests.Request) error

DeleteUser deletes a user by user id.

func (*Database) GetAPIKeys added in v1.1.5

func (db *Database) GetAPIKeys(r *requests.Request) error

GetAPIKeys returns a list of API keys associated with a user.

func (*Database) GetMfaTokens added in v1.0.15

func (db *Database) GetMfaTokens(r *requests.Request) error

GetMfaTokens returns a list of MFA tokens associated with a user.

func (*Database) GetPasswordPolicyRegex added in v1.1.1

func (db *Database) GetPasswordPolicyRegex() string

GetPasswordPolicyRegex returns regex for passwords.

func (*Database) GetPasswordPolicySummary added in v1.1.1

func (db *Database) GetPasswordPolicySummary() string

GetPasswordPolicySummary returns the summary of password policy.

func (*Database) GetPath added in v1.1.1

func (db *Database) GetPath() string

GetPath returns the path to Database.

func (*Database) GetPublicKeys added in v1.0.12

func (db *Database) GetPublicKeys(r *requests.Request) error

GetPublicKeys returns a list of public keys associated with a user.

func (*Database) GetUser added in v1.1.1

func (db *Database) GetUser(r *requests.Request) error

GetUser return an instance of User.

func (*Database) GetUserCount added in v1.0.5

func (db *Database) GetUserCount() int

GetUserCount returns user count.

func (*Database) GetUsernamePolicyRegex added in v1.1.1

func (db *Database) GetUsernamePolicyRegex() string

GetUsernamePolicyRegex returns regex for usernames.

func (*Database) GetUsernamePolicySummary added in v1.1.1

func (db *Database) GetUsernamePolicySummary() string

GetUsernamePolicySummary returns the summary of username policy.

func (*Database) GetUsers added in v1.1.1

func (db *Database) GetUsers(r *requests.Request) error

GetUsers return a list of user identities.

func (*Database) IdentifyUser added in v1.1.4

func (db *Database) IdentifyUser(r *requests.Request) error

IdentifyUser returns user identity and a list of challenges that should be satisfied prior to successfully authenticating a user.

func (*Database) LookupAPIKey added in v1.1.5

func (db *Database) LookupAPIKey(r *requests.Request) error

LookupAPIKey returns username and email associated with the provided API key.

func (*Database) Save added in v1.1.1

func (db *Database) Save() error

Save saves the database.

type Device added in v1.0.20

type Device struct {
	Name string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Type string `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
}

Device is the hardware device on which the WebAuthn Client runs, for example a smartphone, a laptop computer or a desktop computer, and the operating system running on that hardware.

type EmailAddress

type EmailAddress struct {
	Address   string `json:"address,omitempty" xml:"address,omitempty" yaml:"address,omitempty"`
	Confirmed bool   `json:"confirmed,omitempty" xml:"confirmed,omitempty" yaml:"confirmed,omitempty"`
	Domain    string `json:"domain,omitempty" xml:"domain,omitempty" yaml:"domain,omitempty"`
	// contains filtered or unexported fields
}

EmailAddress is an instance of email address

func NewEmailAddress

func NewEmailAddress(s string) (*EmailAddress, error)

NewEmailAddress returns an instance of EmailAddress.

func (*EmailAddress) Primary

func (m *EmailAddress) Primary() bool

Primary returns true is the email is a primary email.

func (*EmailAddress) ToString added in v1.1.1

func (m *EmailAddress) ToString() string

ToString returns string representation of an email address.

type Handle

type Handle struct {
	Github  string `json:"github,omitempty" xml:"github,omitempty" yaml:"github,omitempty"`
	Twitter string `json:"twitter,omitempty" xml:"twitter,omitempty" yaml:"twitter,omitempty"`
}

Handle is the name associated with online services, e.g. Github, Twitter, etc.

func NewHandle

func NewHandle() *Handle

NewHandle returns an instance of Handle

type Image

type Image struct {
	Title string `json:"title,omitempty" xml:"title,omitempty" yaml:"title,omitempty"`
	// Encoded Base64 string
	Body   string       `json:"body,omitempty" xml:"body,omitempty" yaml:"body,omitempty"`
	Config image.Config `json:"config,omitempty" xml:"config,omitempty" yaml:"config,omitempty"`
	Path   string       `json:"path,omitempty" xml:"path,omitempty" yaml:"path,omitempty"`
}

Image is base64 image

func NewImage

func NewImage() *Image

NewImage returns an instance of Image.

type Location

type Location struct {
	Street      string `json:"street,omitempty" xml:"street,omitempty" yaml:"street,omitempty"`
	City        string `json:"city,omitempty" xml:"city,omitempty" yaml:"city,omitempty"`
	State       string `json:"state,omitempty" xml:"state,omitempty" yaml:"state,omitempty"`
	ZipCode     string `json:"zip_code,omitempty" xml:"zip_code,omitempty" yaml:"zip_code,omitempty"`
	Confirmed   bool   `json:"confirmed,omitempty" xml:"confirmed,omitempty" yaml:"confirmed,omitempty"`
	Current     bool   `json:"current,omitempty" xml:"current,omitempty" yaml:"current,omitempty"`
	Domicile    bool   `json:"domicile,omitempty" xml:"domicile,omitempty" yaml:"domicile,omitempty"`
	Residential bool   `json:"residential,omitempty" xml:"residential,omitempty" yaml:"residential,omitempty"`
	Commercial  bool   `json:"commercial,omitempty" xml:"commercial,omitempty" yaml:"commercial,omitempty"`
}

Location repsents a location, e.g. street address.

func NewLocation

func NewLocation() *Location

NewLocation returns an instance of Location.

type LockoutState

type LockoutState struct {
	Enabled   bool      `json:"enabled,omitempty" xml:"enabled,omitempty" yaml:"enabled,omitempty"`
	StartTime time.Time `json:"start_time,omitempty" xml:"start_time,omitempty" yaml:"start_time,omitempty"`
	EndTime   time.Time `json:"end_time,omitempty" xml:"end_time,omitempty" yaml:"end_time,omitempty"`
}

LockoutState indicates whether user identity is temporarily disabled. If the identity is lockedout, when does the lockout end.

func NewLockoutState

func NewLockoutState() *LockoutState

NewLockoutState returns an instance of LockoutState.

type MfaDevice added in v1.0.20

type MfaDevice struct {
	Name   string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Vendor string `json:"vendor,omitempty" xml:"vendor,omitempty" yaml:"vendor,omitempty"`
	Type   string `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
}

MfaDevice is the hardware device associated with MfaToken.

type MfaToken added in v1.0.15

type MfaToken struct {
	ID               string            `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Type             string            `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
	Algorithm        string            `json:"algorithm,omitempty" xml:"algorithm,omitempty" yaml:"algorithm,omitempty"`
	Comment          string            `json:"comment,omitempty" xml:"comment,omitempty" yaml:"comment,omitempty"`
	Secret           string            `json:"secret,omitempty" xml:"secret,omitempty" yaml:"secret,omitempty"`
	Period           int               `json:"period,omitempty" xml:"period,omitempty" yaml:"period,omitempty"`
	Digits           int               `json:"digits,omitempty" xml:"digits,omitempty" yaml:"digits,omitempty"`
	Expired          bool              `json:"expired,omitempty" xml:"expired,omitempty" yaml:"expired,omitempty"`
	ExpiredAt        time.Time         `json:"expired_at,omitempty" xml:"expired_at,omitempty" yaml:"expired_at,omitempty"`
	CreatedAt        time.Time         `json:"created_at,omitempty" xml:"created_at,omitempty" yaml:"created_at,omitempty"`
	Disabled         bool              `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
	DisabledAt       time.Time         `json:"disabled_at,omitempty" xml:"disabled_at,omitempty" yaml:"disabled_at,omitempty"`
	Device           *MfaDevice        `json:"device,omitempty" xml:"device,omitempty" yaml:"device,omitempty"`
	Parameters       map[string]string `json:"parameters,omitempty" xml:"parameters,omitempty" yaml:"parameters,omitempty"`
	Flags            map[string]bool   `json:"flags,omitempty" xml:"flags,omitempty" yaml:"flags,omitempty"`
	SignatureCounter uint32            `json:"signature_counter,omitempty" xml:"signature_counter,omitempty" yaml:"signature_counter,omitempty"`
	// contains filtered or unexported fields
}

MfaToken is a puiblic key in a public-private key pair.

func NewMfaToken added in v1.0.15

func NewMfaToken(req *requests.Request) (*MfaToken, error)

NewMfaToken returns an instance of MfaToken.

func (*MfaToken) Disable added in v1.0.15

func (p *MfaToken) Disable()

Disable disables MfaToken instance.

func (*MfaToken) ValidateCode added in v1.0.18

func (p *MfaToken) ValidateCode(code string) error

ValidateCode validates a passcode

func (*MfaToken) ValidateCodeWithTime added in v1.0.18

func (p *MfaToken) ValidateCodeWithTime(code string, ts time.Time) error

ValidateCodeWithTime validates a passcode at a particular time.

func (*MfaToken) WebAuthnRequest added in v1.1.1

func (p *MfaToken) WebAuthnRequest(payload string) (*WebAuthnAuthenticateRequest, error)

WebAuthnRequest processes WebAuthn requests.

type MfaTokenBundle added in v1.1.1

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

MfaTokenBundle is a collection of public keys.

func NewMfaTokenBundle added in v1.1.1

func NewMfaTokenBundle() *MfaTokenBundle

NewMfaTokenBundle returns an instance of MfaTokenBundle.

func (*MfaTokenBundle) Add added in v1.1.1

func (b *MfaTokenBundle) Add(k *MfaToken)

Add adds MfaToken to MfaTokenBundle.

func (*MfaTokenBundle) Get added in v1.1.1

func (b *MfaTokenBundle) Get() []*MfaToken

Get returns MfaToken instances of the MfaTokenBundle.

func (*MfaTokenBundle) Size added in v1.1.1

func (b *MfaTokenBundle) Size() int

Size returns the number of MfaToken instances in MfaTokenBundle.

type Name

type Name struct {
	First     string `json:"first,omitempty" xml:"first,omitempty" yaml:"first,omitempty"`
	Last      string `json:"last,omitempty" xml:"last,omitempty" yaml:"last,omitempty"`
	Middle    string `json:"middle,omitempty" xml:"middle,omitempty" yaml:"middle,omitempty"`
	Preferred string `json:"preferred,omitempty" xml:"preferred,omitempty" yaml:"preferred,omitempty"`
	Nickname  bool   `json:"nickname,omitempty" xml:"nickname,omitempty" yaml:"nickname,omitempty"`
	Confirmed bool   `json:"confirmed,omitempty" xml:"confirmed,omitempty" yaml:"confirmed,omitempty"`
	Primary   bool   `json:"primary,omitempty" xml:"primary,omitempty" yaml:"primary,omitempty"`
	Legal     bool   `json:"legal,omitempty" xml:"legal,omitempty" yaml:"legal,omitempty"`
	Alias     bool   `json:"alias,omitempty" xml:"alias,omitempty" yaml:"alias,omitempty"`
}

Name represents human name

func NewName

func NewName() *Name

NewName returns an instance of Name.

func ParseName added in v1.1.1

func ParseName(s string) (*Name, error)

ParseName parses name from input.

func (*Name) GetFullName added in v1.0.4

func (n *Name) GetFullName() string

GetFullName returns the primary full name for User.

func (*Name) GetNameClaim

func (n *Name) GetNameClaim() string

GetNameClaim returns name field of a claim.

func (*Name) ToString added in v1.1.1

func (n *Name) ToString() string

ToString returns string represenation of name.

type Organization

type Organization struct {
	ID      uint64   `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Name    string   `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Aliases []string `json:"aliases,omitempty" xml:"aliases,omitempty" yaml:"aliases,omitempty"`
}

Organization is an organized body of people with a particular purpose.

func NewOrganization

func NewOrganization() *Organization

NewOrganization returns an instance of Organization.

type Password

type Password struct {
	Purpose    string    `json:"purpose,omitempty" xml:"purpose,omitempty" yaml:"purpose,omitempty"`
	Algorithm  string    `json:"algorithm,omitempty" xml:"algorithm,omitempty" yaml:"algorithm,omitempty"`
	Hash       string    `json:"hash,omitempty" xml:"hash,omitempty" yaml:"hash,omitempty"`
	Cost       int       `json:"cost,omitempty" xml:"cost,omitempty" yaml:"cost,omitempty"`
	Expired    bool      `json:"expired,omitempty" xml:"expired,omitempty" yaml:"expired,omitempty"`
	ExpiredAt  time.Time `json:"expired_at,omitempty" xml:"expired_at,omitempty" yaml:"expired_at,omitempty"`
	CreatedAt  time.Time `json:"created_at,omitempty" xml:"created_at,omitempty" yaml:"created_at,omitempty"`
	Disabled   bool      `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
	DisabledAt time.Time `json:"disabled_at,omitempty" xml:"disabled_at,omitempty" yaml:"disabled_at,omitempty"`
}

Password is a memorized secret, typically a string of characters, used to confirm the identity of a user.

func NewPassword

func NewPassword(s string) (*Password, error)

NewPassword returns an instance of Password.

func NewPasswordWithOptions added in v1.1.1

func NewPasswordWithOptions(s, purpose, algo string, params map[string]interface{}) (*Password, error)

NewPasswordWithOptions returns an instance of Password based on the provided parameters.

func (*Password) Disable added in v1.0.6

func (p *Password) Disable()

Disable disables Password instance.

func (*Password) Match

func (p *Password) Match(s string) bool

Match returns true when the provided password matches the user.

type PasswordPolicy added in v1.1.1

type PasswordPolicy struct {
	KeepVersions           int  `json:"keep_versions" xml:"keep_versions" yaml:"keep_versions"`
	MinLength              int  `json:"min_length" xml:"min_length" yaml:"min_length"`
	MaxLength              int  `json:"max_length" xml:"max_length" yaml:"max_length"`
	RequireUppercase       bool `json:"require_uppercase" xml:"require_uppercase" yaml:"require_uppercase"`
	RequireLowercase       bool `json:"require_lowercase" xml:"require_lowercase" yaml:"require_lowercase"`
	RequireNumber          bool `json:"require_number" xml:"require_number" yaml:"require_number"`
	RequireNonAlphaNumeric bool `json:"require_non_alpha_numeric" xml:"require_non_alpha_numeric" yaml:"require_non_alpha_numeric"`
	BlockReuse             bool `json:"block_reuse" xml:"block_reuse" yaml:"block_reuse"`
	BlockPasswordChange    bool `json:"block_password_change" xml:"block_password_change" yaml:"block_password_change"`
}

PasswordPolicy represents database password policy.

type Policy added in v1.1.1

type Policy struct {
	Password PasswordPolicy `json:"password,omitempty" xml:"password,omitempty" yaml:"password,omitempty"`
	User     UserPolicy     `json:"user,omitempty" xml:"user,omitempty" yaml:"user,omitempty"`
}

Policy represents database usage policy.

type PublicKey added in v1.0.7

type PublicKey struct {
	ID    string `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Usage string `json:"usage,omitempty" xml:"usage,omitempty" yaml:"usage,omitempty"`
	// Type is any of the following: dsa, rsa, ecdsa, ed25519
	Type           string    `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
	Fingerprint    string    `json:"fingerprint,omitempty" xml:"fingerprint,omitempty" yaml:"fingerprint,omitempty"`
	FingerprintMD5 string    `json:"fingerprint_md5,omitempty" xml:"fingerprint_md5,omitempty" yaml:"fingerprint_md5,omitempty"`
	Comment        string    `json:"comment,omitempty" xml:"comment,omitempty" yaml:"comment,omitempty"`
	Payload        string    `json:"payload,omitempty" xml:"payload,omitempty" yaml:"payload,omitempty"`
	OpenSSH        string    `json:"openssh,omitempty" xml:"openssh,omitempty" yaml:"openssh,omitempty"`
	Expired        bool      `json:"expired,omitempty" xml:"expired,omitempty" yaml:"expired,omitempty"`
	ExpiredAt      time.Time `json:"expired_at,omitempty" xml:"expired_at,omitempty" yaml:"expired_at,omitempty"`
	CreatedAt      time.Time `json:"created_at,omitempty" xml:"created_at,omitempty" yaml:"created_at,omitempty"`
	Disabled       bool      `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
	DisabledAt     time.Time `json:"disabled_at,omitempty" xml:"disabled_at,omitempty" yaml:"disabled_at,omitempty"`
}

PublicKey is a puiblic key in a public-private key pair.

func NewPublicKey added in v1.0.7

func NewPublicKey(r *requests.Request) (*PublicKey, error)

NewPublicKey returns an instance of PublicKey.

func (*PublicKey) Disable added in v1.0.7

func (p *PublicKey) Disable()

Disable disables PublicKey instance.

type PublicKeyBundle added in v1.1.1

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

PublicKeyBundle is a collection of public keys.

func NewPublicKeyBundle added in v1.1.1

func NewPublicKeyBundle() *PublicKeyBundle

NewPublicKeyBundle returns an instance of PublicKeyBundle.

func (*PublicKeyBundle) Add added in v1.1.1

func (b *PublicKeyBundle) Add(k *PublicKey)

Add adds PublicKey to PublicKeyBundle.

func (*PublicKeyBundle) Get added in v1.1.1

func (b *PublicKeyBundle) Get() []*PublicKey

Get returns PublicKey instances of the PublicKeyBundle.

func (*PublicKeyBundle) Size added in v1.1.1

func (b *PublicKeyBundle) Size() int

Size returns the number of PublicKey instances in PublicKeyBundle.

type Registration

type Registration struct {
	User     *User     `json:"user,omitempty" xml:"user,omitempty" yaml:"user,omitempty"`
	Created  time.Time `json:"created,omitempty" xml:"created,omitempty" yaml:"created,omitempty"`
	Aprroved bool      `json:"aprroved,omitempty" xml:"aprroved,omitempty" yaml:"aprroved,omitempty"`
}

Registration is an instance of user registration. Typically used in scenarios where user wants to register for a service. The user provides identity information and waits for an approval.

func NewRegistration

func NewRegistration(user *User) *Registration

NewRegistration returns an instance of Registration.

type Role

type Role struct {
	Name         string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Organization string `json:"organization,omitempty" xml:"organization,omitempty" yaml:"organization,omitempty"`
}

Role is the user role or entitlement in a system.

func NewRole

func NewRole(s string) (*Role, error)

NewRole returns an instance of Role.

func (*Role) String

func (r *Role) String() string

String returns string representation of Role instance.

type User

type User struct {
	ID             string          `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Enabled        bool            `json:"enabled,omitempty" xml:"enabled,omitempty" yaml:"enabled,omitempty"`
	Human          bool            `json:"human,omitempty" xml:"human,omitempty" yaml:"human,omitempty"`
	Username       string          `json:"username,omitempty" xml:"username,omitempty" yaml:"username,omitempty"`
	Title          string          `json:"title,omitempty" xml:"title,omitempty" yaml:"title,omitempty"`
	Name           *Name           `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Organization   *Organization   `json:"organization,omitempty" xml:"organization,omitempty" yaml:"organization,omitempty"`
	Names          []*Name         `json:"names,omitempty" xml:"names,omitempty" yaml:"names,omitempty"`
	Organizations  []*Organization `json:"organizations,omitempty" xml:"organizations,omitempty" yaml:"organizations,omitempty"`
	StreetAddress  []*Location     `json:"street_address,omitempty" xml:"street_address,omitempty" yaml:"street_address,omitempty"`
	EmailAddress   *EmailAddress   `json:"email_address,omitempty" xml:"email_address,omitempty" yaml:"email_address,omitempty"`
	EmailAddresses []*EmailAddress `json:"email_addresses,omitempty" xml:"email_addresses,omitempty" yaml:"email_addresses,omitempty"`
	Passwords      []*Password     `json:"passwords,omitempty" xml:"passwords,omitempty" yaml:"passwords,omitempty"`
	PublicKeys     []*PublicKey    `json:"public_keys,omitempty" xml:"public_keys,omitempty" yaml:"public_keys,omitempty"`
	APIKeys        []*APIKey       `json:"api_keys,omitempty" xml:"api_keys,omitempty" yaml:"api_keys,omitempty"`
	MfaTokens      []*MfaToken     `json:"mfa_tokens,omitempty" xml:"mfa_tokens,omitempty" yaml:"mfa_tokens,omitempty"`
	Lockout        *LockoutState   `json:"lockout,omitempty" xml:"lockout,omitempty" yaml:"lockout,omitempty"`
	Avatar         *Image          `json:"avatar,omitempty" xml:"avatar,omitempty" yaml:"avatar,omitempty"`
	Created        time.Time       `json:"created,omitempty" xml:"created,omitempty" yaml:"created,omitempty"`
	LastModified   time.Time       `json:"last_modified,omitempty" xml:"last_modified,omitempty" yaml:"last_modified,omitempty"`
	Revision       int             `json:"revision,omitempty" xml:"revision,omitempty" yaml:"revision,omitempty"`
	Roles          []*Role         `json:"roles,omitempty" xml:"roles,omitempty" yaml:"roles,omitempty"`
}

User is a user identity.

func NewUser

func NewUser(s string) *User

NewUser returns an instance of User.

func NewUserWithRoles added in v1.1.1

func NewUserWithRoles(username, password, email, fullName string, roles []string) (*User, error)

NewUserWithRoles returns User with additional fields.

func (*User) AddAPIKey added in v1.1.5

func (user *User) AddAPIKey(r *requests.Request) error

AddAPIKey adds API key to a user identity.

func (*User) AddEmailAddress

func (user *User) AddEmailAddress(s string) error

AddEmailAddress returns creates and adds password for a user identity.

func (*User) AddMfaToken added in v1.0.15

func (user *User) AddMfaToken(r *requests.Request) error

AddMfaToken adds MFA token to a user identity.

func (*User) AddName added in v1.0.4

func (user *User) AddName(name *Name) error

AddName adds Name for a user identity.

func (*User) AddPassword

func (user *User) AddPassword(s string, keepVersions int) error

AddPassword returns creates and adds password for a user identity.

func (*User) AddPublicKey added in v1.0.12

func (user *User) AddPublicKey(r *requests.Request) error

AddPublicKey adds public key, e.g. GPG or SSH, to a user identity.

func (*User) AddRole

func (user *User) AddRole(s string) error

AddRole adds a role to a user identity.

func (*User) AddRoles added in v1.1.1

func (user *User) AddRoles(roles []string) error

AddRoles adds roles to a user identity.

func (*User) ChangePassword added in v1.1.1

func (user *User) ChangePassword(r *requests.Request, keepVersions int) error

ChangePassword changes user password.

func (*User) DeleteAPIKey added in v1.1.5

func (user *User) DeleteAPIKey(r *requests.Request) error

DeleteAPIKey deletes an API key associated with a user.

func (*User) DeleteMfaToken added in v1.0.15

func (user *User) DeleteMfaToken(r *requests.Request) error

DeleteMfaToken deletes MFA token associated with a user.

func (*User) DeletePublicKey added in v1.0.14

func (user *User) DeletePublicKey(r *requests.Request) error

DeletePublicKey deletes a public key associated with a user.

func (*User) GetChallenges added in v1.1.4

func (user *User) GetChallenges() []string

GetChallenges returns a list of challenges that should be satisfied prior to successfully authenticating a user.

func (*User) GetFlags added in v1.1.1

func (user *User) GetFlags(r *requests.Request)

GetFlags populates request context with metadata about a user.

func (*User) GetFullName added in v1.0.4

func (user *User) GetFullName() string

GetFullName returns the primary full name for a user.

func (*User) GetMailClaim

func (user *User) GetMailClaim() string

GetMailClaim returns primary email address.

func (*User) GetMetadata added in v1.1.1

func (user *User) GetMetadata() *UserMetadata

GetMetadata returns user metadata.

func (*User) GetNameClaim

func (user *User) GetNameClaim() string

GetNameClaim returns name field of a claim.

func (*User) GetRolesClaim

func (user *User) GetRolesClaim() []string

GetRolesClaim returns name field of a claim.

func (*User) HasEmailAddresses added in v1.1.1

func (user *User) HasEmailAddresses() bool

HasEmailAddresses checks whether a user has email address.

func (*User) HasRole

func (user *User) HasRole(s string) bool

HasRole checks whether a user has a specific role.

func (*User) HasRoles

func (user *User) HasRoles() bool

HasRoles checks whether a user has a role.

func (*User) LookupAPIKey added in v1.1.6

func (user *User) LookupAPIKey(r *requests.Request) error

LookupAPIKey performs the lookup of API key.

func (*User) Revise added in v1.1.5

func (user *User) Revise()

Revise increments revision number and last modified timestamp.

func (*User) Valid

func (user *User) Valid() error

Valid returns true if a user conforms to a standard.

func (*User) VerifyPassword

func (user *User) VerifyPassword(s string) error

VerifyPassword verifies provided password matches to the one in the database.

func (*User) VerifyWebAuthnRequest added in v1.1.4

func (user *User) VerifyWebAuthnRequest(r *requests.Request) error

VerifyWebAuthnRequest authenticated WebAuthn requests.

type UserMetadata added in v1.1.1

type UserMetadata struct {
	ID           string    `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Enabled      bool      `json:"enabled,omitempty" xml:"enabled,omitempty" yaml:"enabled,omitempty"`
	Username     string    `json:"username,omitempty" xml:"username,omitempty" yaml:"username,omitempty"`
	Title        string    `json:"title,omitempty" xml:"title,omitempty" yaml:"title,omitempty"`
	Name         string    `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
	Email        string    `json:"email,omitempty" xml:"email,omitempty" yaml:"email,omitempty"`
	Created      time.Time `json:"created,omitempty" xml:"created,omitempty" yaml:"created,omitempty"`
	LastModified time.Time `json:"last_modified,omitempty" xml:"last_modified,omitempty" yaml:"last_modified,omitempty"`
	Revision     int       `json:"revision,omitempty" xml:"revision,omitempty" yaml:"revision,omitempty"`
	Avatar       string    `json:"avatar,omitempty" xml:"avatar,omitempty" yaml:"avatar,omitempty"`
}

UserMetadata is metadata associated with a user.

type UserMetadataBundle added in v1.1.1

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

UserMetadataBundle is a collection of public users.

func NewUserMetadataBundle added in v1.1.1

func NewUserMetadataBundle() *UserMetadataBundle

NewUserMetadataBundle returns an instance of UserMetadataBundle.

func (*UserMetadataBundle) Add added in v1.1.1

func (b *UserMetadataBundle) Add(k *UserMetadata)

Add adds UserMetadata to UserMetadataBundle.

func (*UserMetadataBundle) Get added in v1.1.1

func (b *UserMetadataBundle) Get() []*UserMetadata

Get returns UserMetadata instances of the UserMetadataBundle.

func (*UserMetadataBundle) Size added in v1.1.1

func (b *UserMetadataBundle) Size() int

Size returns the number of UserMetadata instances in UserMetadataBundle.

type UserPolicy added in v1.1.1

type UserPolicy struct {
	MinLength            int  `json:"min_length" xml:"min_length" yaml:"min_length"`
	MaxLength            int  `json:"max_length" xml:"max_length" yaml:"max_length"`
	AllowNonAlphaNumeric bool `json:"allow_non_alpha_numeric" xml:"allow_non_alpha_numeric" yaml:"allow_non_alpha_numeric"`
	AllowUppercase       bool `json:"allow_uppercase" xml:"allow_uppercase" yaml:"allow_uppercase"`
}

UserPolicy represents database username policy

type WebAuthnAuthenticateRequest added in v1.1.3

type WebAuthnAuthenticateRequest struct {
	ID                string      `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Type              string      `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
	AuthData          *AuthData   `json:"auth_data,omitempty" xml:"auth_data,omitempty" yaml:"auth_data,omitempty"`
	AuthDataEncoded   string      `json:"auth_data_encoded,omitempty" xml:"auth_data_encoded,omitempty" yaml:"auth_data_encoded,omitempty"`
	ClientData        *ClientData `json:"client_data,omitempty" xml:"client_data,omitempty" yaml:"client_data,omitempty"`
	ClientDataEncoded string      `json:"client_data_encoded,omitempty" xml:"client_data_encoded,omitempty" yaml:"client_data_encoded,omitempty"`
	Signature         string      `json:"signature,omitempty" xml:"signature,omitempty" yaml:"signature,omitempty"`
	SignatureEncoded  string      `json:"signature_encoded,omitempty" xml:"signature_encoded,omitempty" yaml:"signature_encoded,omitempty"`
	// contains filtered or unexported fields
}

WebAuthnAuthenticateRequest represents Webauthn Authentication request.

type WebAuthnRegisterRequest added in v1.0.20

type WebAuthnRegisterRequest struct {
	ID                string             `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
	Type              string             `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
	Transports        []string           `json:"transports,omitempty" xml:"transports,omitempty" yaml:"transports,omitempty"`
	Success           bool               `json:"success,omitempty" xml:"success,omitempty" yaml:"success,omitempty"`
	AttestationObject *AttestationObject `json:"attestationObject,omitempty" xml:"attestationObject,omitempty" yaml:"attestationObject,omitempty"`
	ClientData        *ClientData        `json:"clientData,omitempty" xml:"clientData,omitempty" yaml:"clientData,omitempty"`
	Device            *Device            `json:"device,omitempty" xml:"device,omitempty" yaml:"device,omitempty"`
}

WebAuthnRegisterRequest is Webauthn Register request.

Directories

Path Synopsis
cmd
internal
tag
pkg
qr

Jump to

Keyboard shortcuts

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