auth

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: LGPL-2.1 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials  = server.NewHTTPError(http.StatusUnauthorized, "INVALID_CREDENTIALS", "Email or password is incorrect")
	ErrUserBlocked         = server.NewHTTPError(http.StatusUnauthorized, "USER_BLOCKED", "Your account has been blocked and may not login")
	ErrInvalidRefreshToken = server.NewHTTPError(http.StatusUnauthorized, "INVALID_REFRESH_TOKEN", "Invalid refresh token")
	ErrTokenExpired        = server.NewHTTPError(http.StatusUnauthorized, "TOKEN_EXPIRED", "Invalid refresh token")
	ErrInvalidPayloadType  = server.NewHTTPError(http.StatusUnauthorized, "INVALID_PAYLOAD_TYPE", "Invalid payload type")
	ErrRefreshToken        = server.NewHTTPError(http.StatusInternalServerError, "REFRESH_TOKEN_ERROR", "An error occur while refreshing token")
	ErrInvalidGrantType    = server.NewHTTPError(http.StatusBadRequest, "INVALID_GRANT_TYPE", "Invalid grant type")
)

Custom errors

Functions

func NewHTTP

func NewHTTP(svc Service, eg *echo.Group)

NewHTTP attaches handlers to Echo routers under given group

Types

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

Auth represents auth application service

func New

func New(repo *repo.Service, jwt JWT, cr Crypter) *Auth

New creates new auth service

func (*Auth) Login

func (s *Auth) Login(c echo.Context, data Credentials) (*types.AuthToken, error)

Login tries to authenticate the user provided by given credentials

func (*Auth) RefreshToken

func (s *Auth) RefreshToken(c echo.Context, data RefreshTokenData) (*types.AuthToken, error)

RefreshToken refreshes the access token

type AuthenticateInput

type AuthenticateInput struct {
	User    *types.User
	IsLogin bool
}

AuthenticateInput represents internal authenticate data

type Credentials

type Credentials struct {
	// example: loki@gram.sky
	Email string `json:"email" form:"email" validate:"required_without=Username"`
	// example: user123!@#
	Password string `json:"password" form:"password" validate:"required"`

	// This is for SwaggerUI authentication which only support `username` field
	// swagger:ignore
	Username string `json:"username" form:"username"`
	// example: app
	GrantType string `json:"grant_type" form:"grant_type" validate:"required"`
}

Credentials represents login request data swagger:model

type Crypter

type Crypter interface {
	CompareHashAndPassword(string, string) bool
}

Crypter represents security interface

type HTTP

type HTTP struct {
	// contains filtered or unexported fields
}

HTTP represents auth http service

type JWT

type JWT interface {
	GenerateToken(*jwt.TokenInput, *jwt.TokenOutput) error
	ParseToken(string) (*gjwt.Token, error)
}

JWT represents token generator (jwt) interface

type RefreshTokenData

type RefreshTokenData struct {
	RefreshToken string `json:"refresh_token" validate:"required"`
}

RefreshTokenData represents refresh token request data swagger:model

type Service

type Service interface {
	Login(echo.Context, Credentials) (*types.AuthToken, error)
	RefreshToken(echo.Context, RefreshTokenData) (*types.AuthToken, error)
}

Service represents auth service interface

Jump to

Keyboard shortcuts

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