Documentation ¶
Index ¶
- Constants
- func GinMiddleware(tokenSvc tokenSvc) gin.HandlerFunc
- func GinStdMiddleware(conf Config) gin.HandlerFunc
- 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]
- type AuthGSI
- type AuthService
- type Config
- type Controller
- type OAuthProvider
- type OTPStatus
- type OTPSvcI
- type RefreshTokenRequest
- type SendOTPRequest
- type SendOTPResponse
- type Service
- 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 NewOTPSvc ¶
func NewOTPSvc(config otpConfig, smsProvider smsProvider, cache cacheClient) otpSvc
func NewStdClaimsSvc ¶
func NewUserDao ¶
Types ¶
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 ¶
func (a *Controller) VerifyOTP(c *gin.Context, r VerifyOTPRequest) (*VerifyOTPResponse, error)
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 (*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 { 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
Click to show internal directories.
Click to hide internal directories.