Documentation ¶
Index ¶
- Variables
- func AuthHandler(nextFunc func(http.ResponseWriter, *http.Request), options *AuthHandlerOptions) func(http.ResponseWriter, *http.Request)
- func AuthMiddleware(options *AuthHandlerOptions) func(http.Handler) http.Handler
- func ChangePasswordHandler(w http.ResponseWriter, r *http.Request)
- func InitiateAuthHandler(w http.ResponseWriter, r *http.Request)
- func LoginHandler(w http.ResponseWriter, r *http.Request)
- func RegisterHandler(w http.ResponseWriter, r *http.Request)
- type AuthHandlerOptions
- type JWTPayload
- type UserPayload
Constants ¶
This section is empty.
Variables ¶
View Source
var ( RoleAnonymous = "anonymous" RoleMember = "member" RoleAdmin = "admin" )
View Source
var ( JWT_SECRET string AUTH_PATH string )
View Source
var ( ErrInvalidToken = errors.New("unauthorized access (invalid token)") ErrExpiredToken = errors.New("unauthorized access (expired token)") )
View Source
var AuthBucketName = []byte("auth")
View Source
var AuthTokenBucketName = []byte("auth_tokens")
View Source
var UserRoleLevels = map[string]int{ RoleAnonymous: 0, RoleMember: 1, RoleAdmin: 2, }
Functions ¶
func AuthHandler ¶
func AuthHandler(nextFunc func(http.ResponseWriter, *http.Request), options *AuthHandlerOptions) func(http.ResponseWriter, *http.Request)
func AuthMiddleware ¶
func AuthMiddleware(options *AuthHandlerOptions) func(http.Handler) http.Handler
func ChangePasswordHandler ¶
func ChangePasswordHandler(w http.ResponseWriter, r *http.Request)
func InitiateAuthHandler ¶
func InitiateAuthHandler(w http.ResponseWriter, r *http.Request)
func LoginHandler ¶
func LoginHandler(w http.ResponseWriter, r *http.Request)
func RegisterHandler ¶
func RegisterHandler(w http.ResponseWriter, r *http.Request)
Types ¶
type AuthHandlerOptions ¶
type JWTPayload ¶
type JWTPayload struct { ID string `json:"id"` Username string `json:"username"` IssuedAt time.Time `json:"issued_at"` ExpiredAt time.Time `json:"expired_at"` }
func VerifyRequest ¶
func VerifyRequest(r *http.Request, options *AuthHandlerOptions) (*JWTPayload, *userData, string, error)
Verify a http.Request by (1) get bearer token, (2) verify if the token is a valid jwt token, (3) get userData then check if token is still active (4) then check if the user has the proper role if authOption != nil
func (*JWTPayload) Valid ¶
func (payload *JWTPayload) Valid() error
type UserPayload ¶
Click to show internal directories.
Click to hide internal directories.