auth

package
v0.0.0-...-87faeab Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternalServerError = &ErrResponse{
		HTTPStatusCode: http.StatusInternalServerError,
		StatusText:     http.StatusText(http.StatusInternalServerError),
	}
	ErrForbidden = &ErrResponse{
		HTTPStatusCode: http.StatusForbidden,
		StatusText:     http.StatusText(http.StatusForbidden),
	}
)

The list of default error types without specific error message.

View Source
var ErrAPIUnsupported = errors.New("unsupported api version")

ErrAPIUnsupported an unsupported api version.

View Source
var ErrEmailTaken = errors.New("that email is taken")

ErrEmailTaken an already registered email.

View Source
var ErrInvalidEmailOrPassword = errors.New("invalid email or password")

ErrInvalidEmailOrPassword a wrong email or password field.

View Source
var ErrInvalidVerificationToken = errors.New("invalid or expired verification token")

ErrInvalidVerificationToken an expired or invalid verification token.

View Source
var ErrLoginToken = errors.New("invalid or expired login token")

ErrLoginToken an invalid or expired .

View Source
var ErrMissingAPIVersion = errors.New("missing api version header")

ErrMissingAPIVersion a missing api version header with the version text.

View Source
var ErrMissingToken = errors.New("missing authorization header")

ErrMissingToken a missing authorization header with the Bearer token.

View Source
var ErrNoSuchAccount = errors.New("no such account")

ErrNoSuchAccount a non-existent user account.

View Source
var ErrUnknownLogin = errors.New("email not registered")

ErrUnknownLogin an unregistered email field.

Functions

func CheckAPI

func CheckAPI(next http.Handler) http.Handler

CheckAPI http middleware will verify the api version from a http request.

func ErrDuplicateField

func ErrDuplicateField(err error) render.Renderer

ErrDuplicateField returns status 409 Status Conflict including error message.

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

ErrInvalidRequest returns status 422 Unprocessable Entity including error message.

func ErrUnauthorized

func ErrUnauthorized(err error) render.Renderer

ErrUnauthorized renders status 401 Unauthorized with custom error message.

func ErrUnsupportedAPIVersion

func ErrUnsupportedAPIVersion(err error) render.Renderer

ErrUnsupportedAPIVersion returns status 400 Bad Request including error message.

func FromContext

func FromContext(ctx context.Context) (string, bool)

FromContext extracts user id from a Context

func Verifier

func Verifier(cfg *config.Config) func(next http.Handler) http.Handler

Verifier http middleware will verify a jwt string from a http request.

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(_ http.ResponseWriter, r *http.Request) error

Render sets the application-specific error code in AppCode.

type Resource

type Resource struct {
	Store  store.Store
	Config *config.Config
	Mailer *provider.Mailer
}

Resource defines dependencies for auth handlers.

func NewResource

func NewResource(store store.Store, cfg *config.Config, mailer *provider.Mailer) *Resource

NewResource returns a configured authentication resource.

func (Resource) HandleLogin

func (rs Resource) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin login handler for handling login requests

func (Resource) HandleSignup

func (rs Resource) HandleSignup(w http.ResponseWriter, r *http.Request)

HandleSignup signup handler func for handling requests for new accounts.

func (Resource) HandleVerify

func (rs Resource) HandleVerify(w http.ResponseWriter, r *http.Request)

HandleVerify verify the verification code sent with the signup email

func (*Resource) Router

func (rs *Resource) Router() *chi.Mux

Router provides necessary routes for password restricted authentication flow.

Jump to

Keyboard shortcuts

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