authentication

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypeWeb : type of a device
	TypeWeb = "web"

	// TypeIOS : type of a device
	TypeIOS = "ios"

	// TypeAndroid : type of a device
	TypeAndroid = "android"

	// MethodPassword : authentication method by password
	MethodPassword = "password"

	// MethodFacebook : authentication method by facebook
	MethodFacebook = "facebook"

	// MethodGoogle : authentication method by google
	MethodGoogle = "google"

	// InvalidCharactersSetForUsername : forbidden characters in an username.
	InvalidCharactersSetForUsername = "'‘{}"

	// MinimumCharactersForPassword : minimum number of characters in a password.
	MinimumCharactersForPassword = 10

	// MinimumCharactersForUsername : minimum number of characters in a username.
	MinimumCharactersForUsername = 4

	// PrivateKeyLength : length of the generated key code.
	PrivateKeyLength = 128

	// RegisterCodeLength : length of the generated register code.
	RegisterCodeLength = 64

	// PasswordEncryptionSalt : salt used to encrypt the password.
	PasswordEncryptionSalt = "$6$rounds=5000$"

	// PasswordEncryptionSaltLength : length of the salt used to encrypt the password.
	PasswordEncryptionSaltLength = 16

	// ProcessUpdateEmailAddress :
	ProcessUpdateEmailAddress = "update_email"

	// ProcessUpdatePassword :
	ProcessUpdatePassword = "update_password"

	// ProcessVerifyEmailAddress :
	ProcessVerifyEmailAddress = "verify_email"

	// ProcessDeleteAccount :
	ProcessDeleteAccount = "delete_account"

	// ProcessDisableAccount :
	ProcessDisableAccount = "disable_account"
)

Variables

View Source
var (
	// BuildTokenFromID : returns the content of a auth token from its ID.
	BuildTokenFromID BuildTokenFunc

	// ExtraPropertiesForTokenWithID : returns some extra properties to include in the auth token.
	ExtraPropertiesForTokenWithID ExtraPropertiesForTokenWithIDFunc

	// ExtendTokenExpirationDateFromID : extends the expiration date of a auth token from its ID.
	ExtendTokenExpirationDateFromID ExtendTokenExpirationDateFunc
)

Functions

func ComparePassword

func ComparePassword(password, encryptedPassword string) bool

ComparePassword : return true if the password is equal to the encrypted password.

func EncryptPassword

func EncryptPassword(password string) (string, error)

EncryptPassword : encrypt a password.

func GetLastUpdate

func GetLastUpdate(token *jwt.Token) time.Time

GetLastUpdate : returns the token ID from a JWT token.

func GetSignedToken

func GetSignedToken(signingMethod, secret, tokenID string) (string, error)

GetSignedToken : returns a JWT token with some details of an user and an auth token.

func GetTokenID

func GetTokenID(token *jwt.Token) string

GetTokenID : returns the token ID from a JWT token.

func GetUserID

func GetUserID(token *jwt.Token) string

GetUserID : returns the user ID from a JWT token.

func ParseToken

func ParseToken(signedToken, secret string) (*jwt.Token, error)

ParseToken : parses and verifies the authentication token and returns the claims.

func RefreshAuthToken

func RefreshAuthToken(secret, signingMethod, tokenID string, ttl time.Duration) (string, error)

RefreshAuthToken : refreshes and returns an authentication token.

Types

type BuildTokenFunc

type BuildTokenFunc func(tokenID string) (*Token, error)

BuildTokenFunc : function to build a token from its ID.

type Details

type Details struct {
	UserID         string
	Device         Device
	Source         string
	Method         string
	IPAddress      string
	Key            string
	CreationDate   time.Time
	ExpirationDate time.Time
}

Details : struct representing the details of an authentication.

type Device

type Device struct {
	Name                 string       `json:"name"`
	Details              string       `json:"details"`
	Type                 string       `json:"type"`
	UDID                 string       `json:"udid,omitempty"`
	RawName              string       `json:"raw_name"`
	NotificationSettings Notification `json:"notification_settings"`
}

Device : struct of a device.

func (*Device) SetUpNameAndDetails

func (device *Device) SetUpNameAndDetails()

SetUpNameAndDetails : set ups the name and the details.

type ExtendTokenExpirationDateFunc

type ExtendTokenExpirationDateFunc func(tokenID string, ttl time.Duration) error

ExtendTokenExpirationDateFunc : function to extend the expiration date of a token from its ID.

type ExtraPropertiesForTokenWithIDFunc

type ExtraPropertiesForTokenWithIDFunc func(tokenID string) (map[string]string, error)

ExtraPropertiesForTokenWithIDFunc : function to get some extra properties to include in the auth tokens.

type Notification

type Notification struct {
	Token         string   `json:"token,omitempty"`
	Enabled       bool     `json:"enabled"`
	Notifications []string `json:"notifications"`
}

Notification : settings of the notifications on a device.

type Token

type Token struct {
	UserID         string
	Source         string
	PrivateKey     string
	ExpirationDate time.Time
	CreationDate   time.Time
	Other          map[string]interface{}
}

Token : The content of an auth token.

type User

type User struct {
	ID           string
	Username     string
	EmailAddress string
	Locale       string
	PrivateKey   string
	IsEmailValid bool
}

User : struct representing the details of a user.

func (*User) IsSaved

func (user *User) IsSaved() bool

IsSaved : returns true if the struct 'User' is saved.

Jump to

Keyboard shortcuts

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