model

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCredentialEmailEmpty     = errors.New("Credential email cannot be empty")
	ErrCredentialEmailMalformed = errors.New("Credential email is not a valid email address")
	ErrCredentialPassNotMatch   = errors.New("Credential password does not match")
	ErrCredentialProviderEmpty  = errors.New("Credential provider cannot be empty")
)

Credential errors collection

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Token     string
	CSRFToken string
	Expiry    time.Time
}

AccessToken information

type AuthClaims

type AuthClaims struct {
	jwt.StandardClaims
	CSRFToken    string                 `json:"csrf,omitempty"`
	CustomClaims map[string]interface{} `json:"ccm,omitempty"`
}

AuthClaims custom claims to be embedded in Auth Token

type Credential

type Credential struct {
	ID       string                 `json:"id" bson:"_id,omitempty"`
	Email    string                 `json:"email" bson:"email,omitempty"`
	Password string                 `json:"password" bson:"password,omitempty"` //Salted + hashed using bcrypt
	Provider string                 `json:"provider" bson:"provider,omitempty"` //GOOGLE, FACEBOOK, EMAIL
	Claims   map[string]interface{} `json:"custom_claims" bson:"custom_claims"`
}

Credential data model

func (*Credential) Create

func (cred *Credential) Create(email, pass, provider string, claims map[string]interface{}) *Credential

Create initialize new credential

func (*Credential) FromJWT

func (cred *Credential) FromJWT(tokenString string) (AuthClaims, error)

FromJWT parse access token into credential

func (*Credential) GenerateJWT

func (cred *Credential) GenerateJWT() (AccessToken, RefreshToken, error)

GenerateJWT token with one hour token expiration Returns JWT Token, CSRF token, and Expiry time

func (*Credential) Validate

func (cred *Credential) Validate() error

Validate credential data

func (*Credential) VerifyPassword

func (cred *Credential) VerifyPassword(plainPass string) error

VerifyPassword compares credential stored (bcrypt hashed) password, with plain text password

type RefreshToken

type RefreshToken struct {
	ID     string
	Token  string
	Expiry time.Time
}

RefreshToken information

Jump to

Keyboard shortcuts

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