auth

package
v0.0.0-...-470388c Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 20 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 NewLocaleSvc

func NewLocaleSvc(cache cacheClient) *localeSvc

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]

func UserID

func UserID(c *gin.Context) int

Types

type AuthGSI

type AuthGSI interface {
	VerifyToken()
}

dependencies

type AuthService

type AuthService interface {
	UpsertUser(ctx context.Context, u SigupInfo) (*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"`
	Fast2SMS                    fast2sms.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, cacheClient cacheClient) *Controller

func (*Controller) CountryInfo

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 CountryInfoRequest

type CountryInfoRequest struct {
	Apha2Code string `uri:"alpha2Code" binding:"required"`
}

schema

type CountryInfoResponse

type CountryInfoResponse struct {
	Name        string `json:"name"`
	Nationality string `json:"nationality"`
	Code        string `json:"code"`
	DialCode    string `json:"dial_code"`
}

schema

type CountryInfoSource

type CountryInfoSource struct {
	Name        string `json:"en_short_name"`
	Nationality string `json:"nationality"`
	Code        string `json:"alpha_2_code"`
	DialCode    string `json:"dial_code"`
}

dto

type LocalSvc

type LocalSvc interface {
	GetCountryInfo(ctx context.Context, locale string) (*CountryInfoSource, error)
}

dependencies

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"`
	DialCode string `json:"dial_code"`
	Country  string `json:"country"`
	Locale   string `json:"locale"`
}

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, u SigupInfo) (*Token, error)

type SigupInfo

type SigupInfo struct {
	Phone    string
	DialCode string
	Country  string
	Locale   string
}

dto

type Token

type Token struct {
	AccessToken      string
	RefreshToken     string
	ExpiresIn        int64
	RefreshExpiresIn 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, u SigupInfo) (userID int, err error)
	GetByPhone(ctx context.Context, phone string) (userID int, err error)
}

type UserModel

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

type VerifyOTPRequest

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

schema

type VerifyOTPResponse

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

schema

Jump to

Keyboard shortcuts

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