Documentation
¶
Index ¶
- Constants
- Variables
- type AuthMethod
- type Maker
- type PasetoMaker
- func (maker *PasetoMaker) CreateToken(payloadData PayloadData, duration time.Duration, tokenType TokenType) (string, *Payload, error)
- func (maker *PasetoMaker) RevokeTokenAccessToken(token string, ctx context.Context, store sqlc.Store, cache cache.Cache) error
- func (maker *PasetoMaker) VerifyToken(ctx context.Context, cache cache.Cache, token string, tokenType TokenType) (*Payload, error)
- type Payload
- type PayloadData
- type TokenType
Constants ¶
View Source
const ( AccessToken TokenType = "access" RefreshToken TokenType = "refresh" AuthEmailPassword AuthMethod = "email_password" AuthPhone AuthMethod = "phone" AuthGoogle AuthMethod = "google" AuthApple AuthMethod = "apple" DefaultNotBeforeDelay = 15 * time.Minute )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AuthMethod ¶
type AuthMethod string
type Maker ¶
type Maker interface { // CreateToken creates a new token for a specific username and duration CreateToken(payloadData PayloadData, duration time.Duration, tokenType TokenType) (string, *Payload, error) // VerifyToken checks if the token is valid or not VerifyToken(ctx context.Context, cache cache.Cache, token string, tokenType TokenType) (*Payload, error) // Add a revoke endpoint RevokeTokenAccessToken(token string, ctx context.Context, store sqlc.Store, cache cache.Cache) error }
func NewPasetoMaker ¶
type PasetoMaker ¶
type PasetoMaker struct {
// contains filtered or unexported fields
}
func (*PasetoMaker) CreateToken ¶
func (maker *PasetoMaker) CreateToken(payloadData PayloadData, duration time.Duration, tokenType TokenType) (string, *Payload, error)
CreateToken implements Maker.
func (*PasetoMaker) RevokeTokenAccessToken ¶
type Payload ¶
type Payload struct { PayloadData NotBefore time.Time `json:"nbf"` // not before Expires time.Time `json:"exp"` // expiration time IssuedAt time.Time `json:"iat"` // issued at }
func NewPayload ¶
func NewPayload(payload PayloadData, duration time.Duration) (*Payload, error)
func (*Payload) ValidateExpiry ¶
type PayloadData ¶
type PayloadData struct { Role int8 `json:"role"` Subject uuid.UUID `json:"sub"` // subject: the user ID Username string `json:"username,omitempty"` Email string `json:"email,omitempty"` Phone string `json:"phone,omitempty"` EmailVerified bool `json:"email_verified"` SessionID uuid.UUID `json:"session_id,omitempty"` // session ID is optional Issuer string `json:"iss"` // issuer Audience string `json:"aud"` // audience IP string `json:"ip"` // assuming IP is a string for simplicity UserAgent string `json:"user_agent"` MfaPassed bool `json:"mfa_passed"` TokenType TokenType `json:"token_type"` // "access" or "refresh" PhoneVerified bool `json:"phone_verified"` // TODO: Add to db DeviceID string `json:"device_id"` // unique identifier for the device Platform string `json:"platform"` // "android", "ios", "web", "desktop" OSVersion string `json:"os_version"` // OS version of the device AppVersion string `json:"app_version"` // version of your app AuthMethod AuthMethod `json:"auth_method"` // "email", "phone", "google", "apple" }
Click to show internal directories.
Click to hide internal directories.