auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADMIN   int = 1 << 0
	MANAGER int = 1 << 1
	USER    int = 1 << 2
)

Variables

View Source
var (
	ITERATIONS  int
	HASH_LENGTH int
	TIME_PERIOD int64
	ISSUER      string
	JWTSECRET   string
)
View Source
var (
	ManagerRoles []string
	AdminRoles   []string
	UserRoles    []string
)

Functions

func Authenticate

func Authenticate(username, password string, authEntry AuthModel) (string, error)

func Authorize

func Authorize(jwtTokenString string, roleAccess int) error

func GenerateJWT

func GenerateJWT(authEntry AuthModel) (string, error)

func Init

func Init(iter, hashLength int, timePeriod int64, issuer, jwtSecret string, managerRoles, adminRoles, userRoles []string)

Types

type AuthModel

type AuthModel struct {
	Username string `gorm:"not null;unique"`
	Password []byte `gorm:"non null"`
	Role     string `gorm:"non null"`
	Salt     []byte
}

func CreateModel

func CreateModel(username, password, role string) AuthModel

type CustomClaims

type CustomClaims struct {
	User      string `json:"usr"`
	Role      string `json:"eml"`
	ExpiresAt int64  `json:"exp"`
	IssuedAt  int64  `json:"iat"`
	Issuer    string `json:"iss"`
}

func (CustomClaims) Valid

func (c CustomClaims) Valid() error

Jump to

Keyboard shortcuts

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