models

package
Version: v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublicClient client type
	PublicClient string = "public"
	// ConfidentialClient client type
	ConfidentialClient string = "confidential"
)
View Source
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

func GenerateRandomString(n int) string

GenerateRandomString returns a random string with `n` as the length

func IsValid

func IsValid(tagName string, model interface{}) bool

IsValid checks if a `model` entry is valid, given the `tagName` (scope) for validation

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

func RetrieveActionByToken(token string) Action

RetrieveActionByToken obtains an Action entry from its token-string

func RetrieveActionByUUID

func RetrieveActionByUUID(uuid string) Action

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) Save

func (action *Action) Save() error

Save saves an Action entry in a memory store (Redis)

func (*Action) WithinExpirationWindow

func (action *Action) WithinExpirationWindow() bool

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) Authentic

func (client *Client) Authentic(secret string) bool

Authentic checks if a secret is valid for a given Client

func (*Client) BeforeCreate

func (client *Client) BeforeCreate(scope *gorm.Scope) error

BeforeCreate Client model/struct hook

func (*Client) BeforeSave

func (client *Client) BeforeSave(scope *gorm.Scope) error

BeforeSave Client model/struct hook

func (*Client) DefaultRedirectURI

func (client *Client) DefaultRedirectURI() string

DefaultRedirectURI gets the default (first) redirect URI/URL for a client application

func (*Client) UpdateSecret

func (client *Client) UpdateSecret(secret string) error

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

func (session *Session) BeforeCreate(scope *gorm.Scope) error

BeforeCreate Session model/struct hook

func (*Session) BeforeSave

func (session *Session) BeforeSave(scope *gorm.Scope) error

BeforeSave Session model/struct hook

func (*Session) WithinExpirationWindow

func (session *Session) WithinExpirationWindow() bool

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

func (user *User) Authentic(password, passcode string) bool

Authentic checks if a password + passcode combination is valid for a given User

func (*User) BeforeCreate

func (user *User) BeforeCreate(scope *gorm.Scope) error

BeforeCreate User model/struct hook

func (*User) BeforeSave

func (user *User) BeforeSave(scope *gorm.Scope) error

BeforeSave User model/struct hook

func (*User) GenerateCodeSecret

func (user *User) GenerateCodeSecret() *otp.Key

GenerateCodeSecret generates a code secret for an user, in order to generate and validate passcodes

func (*User) GenerateRecoverSecret

func (user *User) GenerateRecoverSecret() string

GenerateRecoverSecret generates a recover secret string for an user

func (*User) UpdatePassword

func (user *User) UpdatePassword(password string) error

UpdatePassword updates an User's password

Jump to

Keyboard shortcuts

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