auth

package
v0.0.0-...-c6dbdfa Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenUnauthorized   = errors.New("token unauthorized")
	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.

View Source
var (
	// ErrUnauthenticated means no credentials are given
	ErrUnauthenticated = &ErrResponse{HTTPStatusCode: http.StatusUnauthorized, StatusText: http.StatusText(http.StatusUnauthorized)}

	// ErrUnauthorized returns status 403 Forbidden for unauthorized request.
	// e.g. "User doesn't have enough privilege"
	ErrUnauthorized = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden)}
)

Functions

func CheckPasswordHash

func CheckPasswordHash(plainPassword, hash string) bool

CheckPasswordHash tests whether a given plainPassword matches the securely hashed one.

func ErrUnauthenticatedWithDetails

func ErrUnauthenticatedWithDetails(err error) render.Renderer

ErrUnauthenticatedWithDetails renders status 401 Unauthorized with custom error message. The request has no credentials at all.

func ErrUnauthorizedWithDetails

func ErrUnauthorizedWithDetails(err error) render.Renderer

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

func GenerateToken(length int) string

GenerateToken generates a random string with a specific length

func HashPassword

func HashPassword(plainPassword string) (string, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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