Documentation ¶
Index ¶
- type Auth
- func (a *Auth) CheckJWTToken(token string) (bool, error)
- func (a *Auth) CheckPassword(hashed string, password string) (bool, error)
- func (a *Auth) GetNewJWTToken(id int64, expirationTime time.Time) (string, error)
- func (a *Auth) GetUserIDFromJWTToken(token string) (int64, error)
- func (a *Auth) HasRoleAdmin(userRoleViews []*db.UserRoleView) bool
- func (a *Auth) HashPassword(password string) (string, error)
- func (a *Auth) RefreshJWTAccessToken(token string, newExpiration time.Time) (string, error)
- type Authenticator
- type Claims
- type EncryptionManager
- type JWTManager
- type RoleManager
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 ¶
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 ¶
CheckPassword checks a given plain password against a hashed password to see if they're compatible
func (*Auth) GetNewJWTToken ¶
GetNewJWTToken generates a new jwt access token for a given user with a given expiration date
func (*Auth) GetUserIDFromJWTToken ¶
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 ¶
HashPassword takes a given password and hashes it for storage in the user table
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