Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrTokenExpired = errors.New("token expired") ErrInvalidAccessToken = errors.New("invalid access token") ErrInvalidRefreshToken = errors.New("invalid refresh token") )
The list of jwt token errors presented to the end user.
var ( // ErrUnauthenticated means no credentials are given ErrUnauthenticated = &ErrResponse{HTTPStatusCode: http.StatusUnauthorized, StatusText: http.StatusText(http.StatusUnauthorized)} // e.g. "User doesn't have enough privilege" ErrUnauthorized = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden)} )
Functions ¶
func CheckPasswordHash ¶
CheckPasswordHash tests whether a given plainPassword matches the securely hashed one.
func ErrUnauthenticatedWithDetails ¶
ErrUnauthenticatedWithDetails renders status 401 Unauthorized with custom error message. The request has no credentials at all.
func ErrUnauthorizedWithDetails ¶
ErrUnauthorizedWithDetails renders status 403 Unauthorized with custom error message. The request is issued with credential, but these are invalid or not sufficient to gain access to a ressource.
func GenerateToken ¶
GenerateToken generates a random string with a specific length
func HashPassword ¶
HashPassword uses bcrypt to securely hash a plain password
Types ¶
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime error HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"status"` // user-level status message AppCode int64 `json:"code,omitempty"` // application-specific error code ErrorText string `json:"error,omitempty"` // application-level error message, for debugging }
ErrResponse renderer type for handling all sorts of errors.
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
Render sets the application-specific error code in AppCode.