auth

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEmail        = utils.ErrInvalidEmail
	ErrInvalidOTP          = errors.New("invalid otp")
	ErrInvalidToken        = errors.New("invalid token")
	ErrInvalidRequestToken = errors.New("invalid request token")
	ErrInvalidAccessToken  = errors.New("invalid access token")
	ErrInvalidRefreshToken = errors.New("invalid refresh token")
)

Functions

This section is empty.

Types

type AuthService

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

func NewAuthService

func NewAuthService(config *Config, emailSvc email.Service) *AuthService

func (*AuthService) GenerateTokensPair

func (s *AuthService) GenerateTokensPair(ctx context.Context, userEmail EmailString, otp OTPString) (string, string, error)

func (*AuthService) IsEnabled

func (s *AuthService) IsEnabled() bool

func (*AuthService) RefreshToken

func (s *AuthService) RefreshToken(ctx context.Context, oldRefreshToken string) (string, string, error)

func (*AuthService) SendOTP

func (s *AuthService) SendOTP(ctx context.Context, userEmail EmailString) error

func (*AuthService) ValidateAccessToken

func (s *AuthService) ValidateAccessToken(ctx context.Context, accessToken string) (*Claims, error)

func (*AuthService) ValidateRefreshToken

func (s *AuthService) ValidateRefreshToken(ctx context.Context, refreshToken string) (*Claims, error)

type AuthTokenType

type AuthTokenType string
const (
	AccessToken  AuthTokenType = "access"
	RefreshToken AuthTokenType = "refresh"
)

type Claims

type Claims struct {
	Type AuthTokenType `json:"type"`
	jwt.RegisteredClaims
}

func ParseClaims

func ParseClaims(tokenString, jwtSecret string) (*Claims, error)

type Config

type Config struct {
	Enabled            bool          `mapstructure:"enabled"`
	TokenIssuer        string        `mapstructure:"token_issuer"`
	RefreshTokenSecret string        `mapstructure:"refresh_token_secret"`
	RefreshTokenExpiry time.Duration `mapstructure:"refresh_token_expiry"`
	AccessTokenSecret  string        `mapstructure:"access_token_secret"`
	AccessTokenExpiry  time.Duration `mapstructure:"access_token_expiry"`
	EmailAddr          string        `mapstructure:"email_addr"`
	EmailOTPLength     int           `mapstructure:"email_otp_length"`
	EmailOTPExpiry     time.Duration `mapstructure:"email_otp_expiry"`
}

func (Config) LogValue

func (c Config) LogValue() slog.Value

func (*Config) Validate

func (c *Config) Validate() error

type EmailString added in v0.7.0

type EmailString = string

type OTPString added in v0.7.0

type OTPString = string

Jump to

Keyboard shortcuts

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