Documentation
¶
Index ¶
- Constants
- func GinMiddleware(tokenSvc tokenSvc) gin.HandlerFunc
- func GinStdMiddleware(conf Config) gin.HandlerFunc
- func NewLocaleSvc(cache cacheClient) *localeSvc
- func NewOTPSvc(config otpConfig, smsProvider smsProvider, cache cacheClient) otpSvc
- func NewStdClaimsSvc(accessTokenValidity, refreshTokenValidity time.Duration, signingKey string) *claimsSvc
- func NewUserDao[U UserModel](db *pgdb.PGDB) *userDao[U]
- func UserID(c *gin.Context) int
- type AuthGSI
- type AuthService
- type Config
- type Controller
- func (a *Controller) CountryInfo(c *gin.Context, r CountryInfoRequest) (*CountryInfoResponse, error)
- func (a *Controller) RefreshToken(c *gin.Context, r RefreshTokenRequest) (*VerifyOTPResponse, error)
- func (a *Controller) SendOTP(c *gin.Context, r SendOTPRequest) (*SendOTPResponse, error)
- func (a *Controller) VerifyOTP(c *gin.Context, r VerifyOTPRequest) (*VerifyOTPResponse, error)
- type CountryInfoRequest
- type CountryInfoResponse
- type CountryInfoSource
- type LocalSvc
- type OAuthProvider
- type OTPStatus
- type OTPSvcI
- type RefreshTokenRequest
- type SendOTPRequest
- type SendOTPResponse
- type Service
- type SigupInfo
- type Token
- type TokenSvc
- type UserDao
- type UserModel
- type VerifyOTPRequest
- type VerifyOTPResponse
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 NewUserDao ¶
Types ¶
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 (a *Controller) CountryInfo(c *gin.Context, r CountryInfoRequest) (*CountryInfoResponse, error)
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 ¶
func (a *Controller) VerifyOTP(c *gin.Context, r VerifyOTPRequest) (*VerifyOTPResponse, error)
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 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 (*Service) RefreshToken ¶
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 VerifyOTPRequest ¶
type VerifyOTPRequest struct {
SendOTPRequest
OTP string `json:"otp" binding:"required,numeric"`
}
schema
Click to show internal directories.
Click to hide internal directories.