Documentation
¶
Index ¶
- Constants
- func Auth(authenticated bool) gin.HandlerFunc
- func CheckDuplicate(name string) (check bool)
- func CreateCookie(token string) *http.Cookie
- func DeleteCookie() *http.Cookie
- func GetPrimarySecret() (string, error)
- func GetSecrets() ([]string, error)
- func HashPassword(password string) (hash []byte, err error)
- func IsInitialized() bool
- func IsRotationActive() bool
- func IsValidName(name string) bool
- func MakeToken(uid uint) (newtoken string, err error)
- func Protect() gin.HandlerFunc
- func RandomPassword() (password string, hash []byte, err error)
- func SetTestMode(enabled bool)
- func UpdatePassword(hash []byte, uid uint) (err error)
- type Authenticator
- type SecretManager
- type TokenClaims
- type User
- func (u *User) ComparePassword(password string) bool
- func (u *User) CreateToken() (newtoken string, err error)
- func (u *User) FromName(name string) (err error)
- func (u *User) IsAuthorized(ib uint) bool
- func (u *User) IsValid() bool
- func (u *User) Password() (err error)
- func (u *User) SetAuthenticated()
- func (u *User) SetID(uid uint)
Constants ¶
const ( // MinSecretLength defines the minimum allowed length for a secret in production MinSecretLength = 16 // MinSecretLengthTest is a shorter length used for tests MinSecretLengthTest = 6 )
const (
// CookieName is the name of the jwt session cookie
CookieName = "session_jwt"
)
Variables ¶
This section is empty.
Functions ¶
func Auth ¶
func Auth(authenticated bool) gin.HandlerFunc
Auth is a gin middleware that checks for session cookie and handles permissions
func CheckDuplicate ¶
CheckDuplicate will check for duplicate name before registering
func CreateCookie ¶ added in v1.3.0
CreateCookie will make a cookie for the JWT
func DeleteCookie ¶ added in v1.3.0
DeleteCookie will delete the JWT cookie
func GetPrimarySecret ¶ added in v1.10.1
GetPrimarySecret returns the primary (new) secret for signing new tokens
func GetSecrets ¶ added in v1.10.1
GetSecrets returns all active secrets for token validation The first return value is always the new secret (primary) The second return value is the old secret (if exists)
func HashPassword ¶
HashPassword will create a bcrypt hash from the given password
func IsInitialized ¶ added in v1.10.1
func IsInitialized() bool
IsInitialized returns true if the new secret is properly configured
func IsRotationActive ¶ added in v1.10.1
func IsRotationActive() bool
IsRotationActive returns true if both old and new secrets are set
func Protect ¶
func Protect() gin.HandlerFunc
Protect will check to see if a user has the correct permissions A route protected by this middleware needs an ib parameter
func RandomPassword ¶ added in v1.3.0
RandomPassword will generate a random password for password resets
func SetTestMode ¶ added in v1.10.1
func SetTestMode(enabled bool)
SetTestMode enables or disables test mode for secret validation
func UpdatePassword ¶ added in v1.3.0
UpdatePassword will update the user password hash in database
Types ¶
type Authenticator ¶
type Authenticator interface {
IsValid() bool
IsAuthorized(ib uint) bool
SetID(uid uint)
SetAuthenticated()
Password() (err error)
ComparePassword(password string) bool
FromName(name string) (err error)
CreateToken() (newtoken string, err error)
}
Authenticator defines the methods for authentication
type SecretManager ¶ added in v1.10.1
type SecretManager struct {
// contains filtered or unexported fields
}
SecretManager handles JWT signing secrets with support for rotation This is now a simple wrapper around the config.Settings.Session All secrets are directly read from config rather than stored internally
type TokenClaims ¶ added in v1.4.0
type TokenClaims struct {
User uint `json:"user_id"`
jwt.RegisteredClaims
}
TokenClaims holds the custom and standard claims for the JWT token
type User ¶
type User struct {
ID uint
Name string
IsAuthenticated bool
// contains filtered or unexported fields
}
User data struct
func (*User) ComparePassword ¶
ComparePassword will compare the supplied password to the hash from the database
func (*User) CreateToken ¶
CreateToken will make a JWT token associated with a user
func (*User) FromName ¶
FromName will get the password and user id from the database for a user name
func (*User) IsAuthorized ¶
IsAuthorized will get the perms and role info from the userid
func (*User) Password ¶
Password will get the password and name from the database for an instantiated user
func (*User) SetAuthenticated ¶
func (u *User) SetAuthenticated()
SetAuthenticated sets a user as authenticated