Documentation ¶
Index ¶
- Constants
- func GenerateRandomString(n int) string
- func IsValid(tagName string, model interface{}) bool
- type Action
- type Client
- type Language
- type Model
- type Session
- type Tokens
- type User
- func (user *User) Authentic(password, passcode string) bool
- func (user *User) BeforeCreate(scope *gorm.Scope) error
- func (user *User) BeforeSave(scope *gorm.Scope) error
- func (user *User) GenerateCodeSecret() *otp.Key
- func (user *User) GenerateRecoverSecret() string
- func (user *User) UpdatePassword(password string) error
Constants ¶
const ( // PublicClient client type PublicClient string = "public" // ConfidentialClient client type ConfidentialClient string = "confidential" )
const ( // AccessToken token type AccessToken string = "access_token" // RefreshToken token type RefreshToken string = "refresh_token" // GrantToken token type GrantToken string = "grant_token" // PublicScope session scope PublicScope string = "public" // ReadScope session scope ReadScope string = "read" // ReadWriteScope session scope ReadWriteScope string = "read_write" )
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomString ¶
GenerateRandomString returns a random string with `n` as the length
Types ¶
type Action ¶
type Action struct { UUID string `validate:"omitempty,uuid4" json:"uuid"` User User `validate:"exists" json:"-"` UserID uint `json:"user_id"` Client Client `validate:"exists" json:"-"` ClientID uint `json:"client_id"` Moment int64 `json:"moment"` ExpiresIn int64 `json:"expires_in"` IP string `validate:"required" json:"ip"` UserAgent string `validate:"required" json:"user_agent"` Token string `validate:"omitempty,alphanum" json:"token"` Scopes string `validate:"required,scope" json:"scopes"` CreatedAt time.Time `json:"created_at"` }
Action is a model/struct used to represent ephemeral actions/sessions in the application
func RetrieveActionByToken ¶
RetrieveActionByToken obtains an Action entry from its token-string
func RetrieveActionByUUID ¶
RetrieveActionByUUID obtains an Action entry from its UUID
func (*Action) Delete ¶
func (action *Action) Delete()
Delete deletes an Action entry in a memory store (Redis)
func (*Action) WithinExpirationWindow ¶
WithinExpirationWindow checks if a Action entry is still valid (time-based)
type Client ¶
type Client struct { Model UUID string `gorm:"not null;unique;index" validate:"omitempty,uuid4" json:"id"` Name string `gorm:"not null;unique;index" validate:"required,min=3,max=20" json:"name"` Description string `json:"description"` Key string `gorm:"not null;unique;index" json:"-"` Secret string `gorm:"not null" validate:"required" json:"-"` Scopes string `gorm:"not null" validate:"required" json:"-"` CanonicalURI string `gorm:"not null" validate:"required,canonical" json:"uri"` RedirectURI string `gorm:"not null" validate:"required,redirect" json:"redirect"` Type string `gorm:"not null" validate:"required,client" json:"-"` }
Client is the client application model/struct
func (*Client) BeforeCreate ¶
BeforeCreate Client model/struct hook
func (*Client) BeforeSave ¶
BeforeSave Client model/struct hook
func (*Client) DefaultRedirectURI ¶
DefaultRedirectURI gets the default (first) redirect URI/URL for a client application
func (*Client) UpdateSecret ¶
UpdateSecret updates an Client's secret
type Language ¶
type Language struct { Model Name string `gorm:"not null;unique;index" validate:"required,min=3"` IsoCode string `gorm:"not null;unique" validate:"required,min=2,max=5"` }
Language model/struct represents a Language option through the Application UI
type Model ¶
type Model struct { ID uint `gorm:"primary_key" json:"-"` CreatedAt time.Time `gorm:"not null" json:"-"` UpdatedAt time.Time `json:"-"` }
Model is the base model/struct for any model in the application/system
type Session ¶
type Session struct { Model UUID string `gorm:"not null;unique;index" validate:"omitempty,uuid4" json:"-"` User User `gorm:"not null" validate:"exists" json:"-"` UserID uint `gorm:"not null" json:"-"` Client Client `gorm:"not null" validate:"exists" json:"-"` ClientID uint `gorm:"not null" json:"-"` Moment int64 `gorm:"not null" json:"moment"` ExpiresIn int64 `gorm:"not null;default:0" json:"expires_in"` IP string `gorm:"not null;index" validate:"required" json:"-"` UserAgent string `gorm:"not null" validate:"required" json:"-"` Invalidated bool `gorm:"not null;default:false"` Token string `gorm:"not null;unique;index" validate:"omitempty,alphanum" json:"token"` TokenType string `gorm:"not null;index" validate:"required,token" json:"token_type"` Scopes string `gorm:"not null" validate:"required,scope" json:"-"` }
Session model/struct
func (*Session) BeforeCreate ¶
BeforeCreate Session model/struct hook
func (*Session) BeforeSave ¶
BeforeSave Session model/struct hook
func (*Session) WithinExpirationWindow ¶
WithinExpirationWindow checks if a Session entry is still valid (time-based)
type Tokens ¶
type Tokens interface {
WithinExpirationWindow()
}
Tokens interface defines methods/actions for checking session-tokens
time-based validity
type User ¶
type User struct { Model UUID string `gorm:"not null;unique;index" validate:"omitempty,uuid4" json:"-"` PublicID string `gorm:"not null;unique;index" json:"public_id"` Username string `gorm:"not null;unique;index" validate:"required,alphanum,max=60" json:"-"` FirstName string `gorm:"not null" validate:"required,min=3,max=20" essential:"required,min=3,max=20" json:"first_name"` LastName string `gorm:"not null" validate:"required,min=3,max=20" essential:"required,min=3,max=20" json:"last_name"` Email string `gorm:"not null;unique;index" validate:"required,email" essential:"required,email" json:"email"` Passphrase string `gorm:"not null" validate:"required" essential:"required,min=10" json:"-"` Active bool `gorm:"not null;default:false" json:"active"` Admin bool `gorm:"not null;default:false" json:"-"` Client Client `gorm:"not null" validate:"exists" json:"-"` ClientID uint `gorm:"not null" json:"-"` Language Language `gorm:"not null" validate:"exists" json:"-"` LanguageID uint `gorm:"not null" json:"-"` TimezoneIdentifier string `gorm:"not null;default:'GMT'" json:"timezone_identifier"` CodeSecret string `gorm:"not null" validate:"required" json:"-"` RecoverSecret string `gorm:"not null" validate:"required" json:"-"` }
User model/struct
func (*User) Authentic ¶
Authentic checks if a password + passcode combination is valid for a given User
func (*User) BeforeCreate ¶
BeforeCreate User model/struct hook
func (*User) BeforeSave ¶
BeforeSave User model/struct hook
func (*User) GenerateCodeSecret ¶
GenerateCodeSecret generates a code secret for an user, in order to generate and validate passcodes
func (*User) GenerateRecoverSecret ¶
GenerateRecoverSecret generates a recover secret string for an user
func (*User) UpdatePassword ¶
UpdatePassword updates an User's password