auth

package
v0.0.0-...-bd48299 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct{}

Auth is the struct that we're going to use to implement all of out Authenticator interfaces

func New

func New() *Auth

New makes a new Auth struct which implements all of the "Authenticator" methods

func (*Auth) CheckJWTToken

func (a *Auth) CheckJWTToken(token string) (bool, error)

CheckJWTToken takes a jwt token string and checks if is still valid (i.e. didn't expire, of the right sign format, etc)

func (*Auth) CheckPassword

func (a *Auth) CheckPassword(hashed string, password string) (bool, error)

CheckPassword checks a given plain password against a hashed password to see if they're compatible

func (*Auth) GetNewJWTToken

func (a *Auth) GetNewJWTToken(id int64, expirationTime time.Time) (string, error)

GetNewJWTToken generates a new jwt access token for a given user with a given expiration date

func (*Auth) GetUserIDFromJWTToken

func (a *Auth) GetUserIDFromJWTToken(token string) (int64, error)

GetUserIDFromJWTToken extracts the stored userID fromt the claims in a JWT token

func (*Auth) HasRoleAdmin

func (a *Auth) HasRoleAdmin(userRoleViews []*db.UserRoleView) bool

HasRoleAdmin checks to see whether or not user's fetched user roles has the "admin" role

func (*Auth) HashPassword

func (a *Auth) HashPassword(password string) (string, error)

HashPassword takes a given password and hashes it for storage in the user table

func (*Auth) RefreshJWTAccessToken

func (a *Auth) RefreshJWTAccessToken(token string, newExpiration time.Time) (string, error)

RefreshJWTAccessToken takes an existing access jwt token (likely expired) And updates its expiration time so that the token is still valid for future use

type Authenticator

type Authenticator interface {
	JWTManager
	EncryptionManager
	RoleManager
}

Authenticator combines all of the various aspects of our auth layer into one

type Claims

type Claims struct {
	UserID int
	jwt.StandardClaims
}

Claims is a custom extended jwt.StandardClaims to include a user's email address as part of the claims

type EncryptionManager

type EncryptionManager interface {
	HashPassword(password string) (string, error)
	CheckPassword(hashed string, password string) (bool, error)
}

EncryptionManager describes all of the methods used for handling the encryption side of our auth layer

type JWTManager

type JWTManager interface {
	GetNewJWTToken(id int64, expiration time.Time) (string, error)
	RefreshJWTAccessToken(token string, expiration time.Time) (string, error)
	CheckJWTToken(token string) (bool, error)
	GetUserIDFromJWTToken(token string) (int64, error)
}

JWTManager describes all of the methods used for handling the JSON web token side of our auth layer

type RoleManager

type RoleManager interface {
	HasRoleAdmin(userRoleViews []*db.UserRoleView) bool
}

RoleManager describes all of the methods used for handling the permissions/roles auth layer

Jump to

Keyboard shortcuts

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