auth

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Login

func Login(
	log *slog.Logger, refreshTTL time.Duration, usrProvider UserProvider,
) func(w http.ResponseWriter, r *http.Request)

Login @Summary Sign In @Tags auth @Description Sign in to the system @Accept json @Produce json @Param input body Request true "account info" @Success 200 {object} Response @Router /login [post]

func Refresh

func Refresh(
	log *slog.Logger, refresher UserRefresher,
) func(w http.ResponseWriter, r *http.Request)

Refresh @Summary Refresh @Tags auth @Description Refresh access token @Accept json @Produce json @Param input body Request true "refresh token" @Success 200 {object} Response @Router /refresh [post]

func Register

func Register(
	log *slog.Logger, reg UserRegister,
) func(w http.ResponseWriter, r *http.Request)

Register @Summary Register @Tags auth @Description Register new user @Accept json @Produce json @Param input body Request true "user info" @Success 200 {object} Response @Router /register [post]

Types

type Auth

type Auth interface {
	UserProvider
	UserRefresher
	UserRegister
}

type LoginResp

type LoginResp struct {
	Jwt string `json:"jwt"`
}

type RefreshResp

type RefreshResp struct {
	AccessToken string `json:"access_token"`
}

type RegisterResp

type RegisterResp struct {
	Id string `json:"id"`
	resp.Response
}

type UserProvider

type UserProvider interface {
	LoginUser(context.Context, dto.LoginReq) (jwt *dto.JWT, err error)
}

type UserRefresher

type UserRefresher interface {
	RefreshToken(context.Context, dto.RefreshReq) (accessToken string, err error)
}

type UserRegister

type UserRegister interface {
	RegisterUser(context.Context, dto.RegisterReq) (id string, err error)
}

Jump to

Keyboard shortcuts

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