auth

package
v0.0.0-...-52ce4d9 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxKeyTokenClaims string = "tokenClaims"
	CtxKeyUserID      string = "userID"
)

Variables

This section is empty.

Functions

func GinMiddleware

func GinMiddleware(tokenSvc tokenSvc) gin.HandlerFunc

func GinStdMiddleware

func GinStdMiddleware(conf Config) gin.HandlerFunc

func NewOTPSvc

func NewOTPSvc(config otpConfig, smsProvider smsProvider, cache cacheClient) otpSvc

func NewStdClaimsSvc

func NewStdClaimsSvc(accessTokenValidity, refreshTokenValidity time.Duration, signingKey string) *claimsSvc

func NewUserDao

func NewUserDao[U UserModel](db *pgdb.PGDB) *userDao[U]

Types

type AuthGSI

type AuthGSI interface {
	VerifyToken()
}

dependencies

type AuthService

type AuthService interface {
	UpsertUser(ctx context.Context, phone string) (*Token, error)
	RefreshToken(ctx context.Context, refreshToken string) (*Token, error)
}

dependencies

type Config

type Config struct {
	SecretKey                   string        `validate:"required" log:"-"`
	AccessTokenValiditySeconds  int           `validate:"required"`
	RefreshTokenValiditySeconds int           `validate:"required"`
	OTP                         otpConfig     `validate:"required"`
	Twilio                      twilio.Config `validate:"required"`
}

Config holds the configuration for auth service

type Controller

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

func NewController

func NewController(authSvc AuthService, otpSvc OTPSvcI) *Controller

func (*Controller) RefreshToken

func (a *Controller) RefreshToken(c *gin.Context, r RefreshTokenRequest) (*VerifyOTPResponse, error)

func (*Controller) SendOTP

func (a *Controller) SendOTP(c *gin.Context, r SendOTPRequest) (*SendOTPResponse, error)

func (*Controller) VerifyOTP

type OAuthProvider

type OAuthProvider interface {
	Initiate()
	Verify()
}

dependencies

type OTPStatus

type OTPStatus struct {
	RetryAfter  int
	AttemptLeft int
}

dto

type OTPSvcI

type OTPSvcI interface {
	Send(ctx context.Context, phone string) (*OTPStatus, error)
	Verify(ctx context.Context, phone, otp string) error
}

dependencies

type RefreshTokenRequest

type RefreshTokenRequest struct {
	RefreshToken string `json:"refresh_token" binding:"required"`
}

schema

type SendOTPRequest

type SendOTPRequest struct {
	Phone string `json:"phone" binding:"required"`
}

schema

type SendOTPResponse

type SendOTPResponse struct {
	RetryAfter  int `json:"retry_after"`
	AttemptLeft int `json:"attempt_left"`
}

schema

type Service

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

func NewService

func NewService(config Config, userDao UserDao) *Service

func (*Service) RefreshToken

func (s *Service) RefreshToken(ctx context.Context, refreshToken string) (*Token, error)

func (*Service) UpsertUser

func (s *Service) UpsertUser(ctx context.Context, phone string) (*Token, error)

type Token

type Token struct {
	AccessToken  string
	RefreshToken string
	ExpiresIn    int64
}

dto

type TokenSvc

type TokenSvc interface {
	NewAccessTokenClaims(subject string) jwt.Claims
	NewRefreshTokenClaims(subject string) jwt.Claims
	VerifyToken(token string) (*jwt.Token, error)
	ValidateAccessTokenClaims(claims jwt.Claims) (subject string, err error)
	ValiateRefreshTokenClaims(claims jwt.Claims) (subject string, err error)
}

type UserDao

type UserDao interface {
	Create(ctx context.Context, phone string) (userID int, err error)
	GetByPhone(ctx context.Context, phone string) (userID int, err error)
}

type UserModel

type UserModel interface {
	SetPhone(string) UserModel
	PK() int
	ResourceName() string
}

type VerifyOTPRequest

type VerifyOTPRequest struct {
	Phone string `json:"phone" binding:"required"`
	OTP   string `json:"otp" binding:"required,numeric"`
}

schema

type VerifyOTPResponse

type VerifyOTPResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresAt    int64  `json:"expires_in"`
}

schema

Jump to

Keyboard shortcuts

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