Documentation
¶
Index ¶
- Constants
- Variables
- func Base64URLDecode(s string) ([]byte, error)
- func Base64URLEncode(b []byte) string
- func Decode(s string) ([]byte, error)
- func DecodeJSON(s string, v interface{}) error
- func Encode(v []byte) string
- func EncodeJSON(data interface{}) (string, error)
- func ValidEmailAddress(email string) bool
- func ValidOptions(options Options) bool
- func ValidPhonenumber(phone string) bool
- func ValidUsername(username string) bool
- type AccessToken
- type Login
- type Options
- func (o Options) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (o Options) GormDataType() string
- func (o Options) GormValue(ctx context.Context, db *gorm.DB) clause.Expr
- func (o Options) MarshalJSON() ([]byte, error)
- func (o *Options) Scan(val interface{}) error
- func (o *Options) UnmarshalJSON(b []byte) error
- func (o *Options) Value() (driver.Value, error)
- type SignedPublicKey
- type Totp
- type User
- type UserType
- type Users
Constants ¶
const ( // Validation constants MaxNameSize = 255 MaxValueSize = 4096 MaxEmailLocalPartSize = 64 MaxEmailServerPartSize = 255 )
Variables ¶
var ( // Regular expression list // Meant to provide a simple syntax check; e.g. good luck validating // emails UsernameRe = regexp.MustCompile(`^\w(?:\S?\w){2,127}$`) EmailAddressRe = regexp.MustCompile(`^.+@.+\..+$`) PhoneRe = regexp.MustCompile(`^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$`) // Errors list ErrorInvalidName = fmt.Errorf("Name exceeds max length of %d", MaxNameSize) ErrorInvalidEmailAddress = errors.New("Email address is invalid") ErrorInvalidUsername = errors.New("Username is invalid") ErrorInvalidPhonenumber = errors.New("Phonenumber is invalid") ErrorInvalidOptions = errors.New("Options contain invalid key-value pair") )
var UserTypeStrings = []string{
"USER",
"GUEST",
"ADMIN",
}
UserTypeStrings is a list of string representations of user types.
Functions ¶
func Base64URLDecode ¶
Base64URLEncode returns the bytes for the given base64 URL encoded string.
func Base64URLEncode ¶
Base64URLEncode returns a base64 URL encoded string for the given bytes.
func DecodeJSON ¶
DecodeJSON sets the given data struct to the decoded bytes of the given string.
func EncodeJSON ¶
EncodeJSON returns the encoded string for a given data struct.
func ValidEmailAddress ¶
ValidEmailAddress return true if the given email address is valid.
func ValidOptions ¶
ValidOptions returns true if the options map is valid.
func ValidPhonenumber ¶
ValidPhonenumber returns true if the given phonenumber is valid.
func ValidUsername ¶
ValidUsername returns true if the given username is valid.
Types ¶
type AccessToken ¶
type AccessToken struct { Token string `json:"token"` RefreshToken string `json:"refresh_token"` OtpRequired bool `json:"otp_required"` }
AccessToken represents an access and refresh tokens.
type Options ¶
Options represents a map of optional user attributes.
func (Options) GormDBDataType ¶
GormDBDataType returns the DB datatype for the given database's dialect. This implements the migrator.GormDataTypeInterface interface.
func (Options) GormDataType ¶
GormDataType returns the GORM datatype of the options. This implements the schema.GormDataTypeInterface interface.
func (Options) GormValue ¶
GormValue returns the GORM expression for the given database and options. This implements the gorm.Valuer interface.
func (Options) MarshalJSON ¶
MarshalJSON marshals the options value and encodes as JSON.
func (*Options) Scan ¶
Scan scans the given bytes or string value into the given options. This implements the sql.Scanner interface.
func (*Options) UnmarshalJSON ¶
UnmarshalJSON unmarshals the given JSON bytes into the options.
type SignedPublicKey ¶
type SignedPublicKey struct { Id string `json:"id"` Alg string `json:"alg"` KTy string `json:"kty"` User string `json:"user"` PublicKey string `json:"public_key"` Signature string `json:"signature"` }
SignedPublicKey respresents a public key authentication request.
func (*SignedPublicKey) SigningAlgorithm ¶
func (key *SignedPublicKey) SigningAlgorithm() (algorithms.SigningAlgorithm, error)
SigningAlgorithm returns the signing algorithm of the signed public key.
func (*SignedPublicKey) SigningString ¶
func (key *SignedPublicKey) SigningString() (string, error)
SigningString returns the encoded signing string of the signed public key.
func (*SignedPublicKey) Valid ¶
func (key *SignedPublicKey) Valid(secret []byte) error
Valid verifies the signed public key's signature using the given secret.
type User ¶
type User struct { ID uint `gorm:"primarykey" json:"-"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Password string `json:"password"` Email string `json:"email"` Username string `json:"username"` Phone string `json:"phone"` UserType string `json:"user_type"` UserId string `json:"user_id"` Token string `json:"-"` RefreshToken string `json:"-"` TotpEnabled bool `json:"totp_enabled"` Totp string `json:"-"` Options Options `gorm:"serializer:json" json:"options"` PublicKey string `json:"public_key"` }
User models a user in the authentication service.
type UserType ¶
type UserType int
UserType represents a user's type.
func ToUserType ¶
ToUserType returns the UserType for a value user type string. Otherwise an error is returned.