Documentation
¶
Index ¶
- Constants
- func GetPasetoObj() *paseto.V2
- func WithValidateEssentialTags(claim *claims.StandardClaims, extra map[string]any) error
- type PasetoManager
- func (p *PasetoManager) FetchBasicToken(options ...claims.StandardClaimsOption) result.Result[TokenDetails]
- func (p *PasetoManager) FetchRefreshToken(options ...claims.StandardClaimsOption) result.Result[TokenDetails]
- func (p *PasetoManager) FetchToken(options ...claims.StandardClaimsOption) result.Result[TokenDetails]
- func (p *PasetoManager) PasetoMiddlewareOption() *PasetoMiddlewareOptions
- func (p *PasetoManager) ValidateToken(token string, extra map[string]any, validators ...TokenValidator) result.Result[claims.StandardClaims]
- type PasetoMiddlewareOption
- func WithAuthHeader(header string) PasetoMiddlewareOption
- func WithAutoRefresh(enabled bool) PasetoMiddlewareOption
- func WithExcludedOptions(options *structures.ExcludedOptions) PasetoMiddlewareOption
- func WithNewAuthHeader(header string) PasetoMiddlewareOption
- func WithRefreshThreshold(duration time.Duration) PasetoMiddlewareOption
- type PasetoMiddlewareOptions
- func (p *PasetoMiddlewareOptions) AddExcludedEvent(event *string)
- func (p *PasetoMiddlewareOptions) AddExcludedRecord(record *string)
- func (p *PasetoMiddlewareOptions) AddExcludedService(service *string)
- func (p *PasetoMiddlewareOptions) AuthHeader() string
- func (p *PasetoMiddlewareOptions) ExcludedOptions() *structures.ExcludedOptions
- func (p *PasetoMiddlewareOptions) HasExcludedOption() bool
- func (p *PasetoMiddlewareOptions) IsAutoRefresh() bool
- func (p *PasetoMiddlewareOptions) NewAuthHeader() string
- func (p *PasetoMiddlewareOptions) RefreshThreshold() time.Duration
- type PasetoOption
- func WithAccessTokenExpiry(accessToken time.Duration) PasetoOption
- func WithBasicTokenExpiry(basicToken time.Duration) PasetoOption
- func WithExpiry(accessToken, refreshToken time.Duration) PasetoOption
- func WithIssuer(issuer string) PasetoOption
- func WithKeys(privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey) PasetoOption
- func WithPasetoMiddlewareOption(opts ...PasetoMiddlewareOption) PasetoOption
- func WithPrivateKey(privateKey ed25519.PrivateKey) PasetoOption
- func WithPublicKey(publicKey ed25519.PublicKey) PasetoOption
- func WithRefreshTokenExpiry(refreshToken time.Duration) PasetoOption
- type TokenDetails
- type TokenValidator
Constants ¶
const (
RefreshThreshold = 5 * time.Minute
)
Variables ¶
This section is empty.
Functions ¶
func WithValidateEssentialTags ¶
func WithValidateEssentialTags(claim *claims.StandardClaims, extra map[string]any) error
WithValidateEssentialTags ensures core payload fields are correct.
Types ¶
type PasetoManager ¶
type PasetoManager struct {
// contains filtered or unexported fields
}
**Paseto Wrapper Type**
func NewPasetoManager ¶
func NewPasetoManager(opts ...PasetoOption) *PasetoManager
**Constructor Using Option Pattern**
func (*PasetoManager) FetchBasicToken ¶
func (p *PasetoManager) FetchBasicToken(options ...claims.StandardClaimsOption) result.Result[TokenDetails]
FetchBasicToken generates a new basic token
func (*PasetoManager) FetchRefreshToken ¶
func (p *PasetoManager) FetchRefreshToken(options ...claims.StandardClaimsOption) result.Result[TokenDetails]
FetchRefreshToken generates a new refresh token
func (*PasetoManager) FetchToken ¶
func (p *PasetoManager) FetchToken(options ...claims.StandardClaimsOption) result.Result[TokenDetails]
FetchToken generates a new access token
func (*PasetoManager) PasetoMiddlewareOption ¶
func (p *PasetoManager) PasetoMiddlewareOption() *PasetoMiddlewareOptions
PasetoMiddlewareOption returns the middleware options for the PASETO wrapper.
func (*PasetoManager) ValidateToken ¶
func (p *PasetoManager) ValidateToken( token string, extra map[string]any, validators ...TokenValidator, ) result.Result[claims.StandardClaims]
ValidateToken validates a token and runs multiple custom validators.
type PasetoMiddlewareOption ¶
type PasetoMiddlewareOption func(*PasetoMiddlewareOptions)
PasetoMiddlewareOption sets options for the Paseto middleware.
func WithAuthHeader ¶
func WithAuthHeader(header string) PasetoMiddlewareOption
WithAuthHeader sets the authorization header name
func WithAutoRefresh ¶
func WithAutoRefresh(enabled bool) PasetoMiddlewareOption
WithAutoRefresh enables token auto-refresh
func WithExcludedOptions ¶
func WithExcludedOptions(options *structures.ExcludedOptions) PasetoMiddlewareOption
WithExcludedOptions sets the excluded options for the PASETO wrapper.
func WithNewAuthHeader ¶
func WithNewAuthHeader(header string) PasetoMiddlewareOption
WithNewAuthHeader sets the new token response header name
func WithRefreshThreshold ¶
func WithRefreshThreshold(duration time.Duration) PasetoMiddlewareOption
WithRefreshThreshold sets the time before expiration to trigger refresh
type PasetoMiddlewareOptions ¶
type PasetoMiddlewareOptions struct {
// contains filtered or unexported fields
}
PasetoMiddlewareOptions defines options for the Paseto middleware.
func (*PasetoMiddlewareOptions) AddExcludedEvent ¶
func (p *PasetoMiddlewareOptions) AddExcludedEvent(event *string)
AddExcludedEvent adds an event to the list of excluded events.
func (*PasetoMiddlewareOptions) AddExcludedRecord ¶
func (p *PasetoMiddlewareOptions) AddExcludedRecord(record *string)
AddExcludedRecord adds a record to the list of excluded records.
func (*PasetoMiddlewareOptions) AddExcludedService ¶
func (p *PasetoMiddlewareOptions) AddExcludedService(service *string)
AddExcludedService adds a service to the list of excluded services.
func (*PasetoMiddlewareOptions) AuthHeader ¶
func (p *PasetoMiddlewareOptions) AuthHeader() string
AuthHeader returns the name of the authorization header.
func (*PasetoMiddlewareOptions) ExcludedOptions ¶
func (p *PasetoMiddlewareOptions) ExcludedOptions() *structures.ExcludedOptions
ExcludedOptions returns the list of options to exclude from token validation.
func (*PasetoMiddlewareOptions) HasExcludedOption ¶
func (p *PasetoMiddlewareOptions) HasExcludedOption() bool
HasExcludedOption returns true if the list of excluded options is not empty.
func (*PasetoMiddlewareOptions) IsAutoRefresh ¶
func (p *PasetoMiddlewareOptions) IsAutoRefresh() bool
Getters for PasetoMiddlewareOptions fields.
func (*PasetoMiddlewareOptions) NewAuthHeader ¶
func (p *PasetoMiddlewareOptions) NewAuthHeader() string
NewAuthHeader returns the name of the header for the new token (if auto-refresh is enabled).
func (*PasetoMiddlewareOptions) RefreshThreshold ¶
func (p *PasetoMiddlewareOptions) RefreshThreshold() time.Duration
RefreshThreshold returns the time threshold before token expiration to trigger refresh.
type PasetoOption ¶
type PasetoOption func(*PasetoManager)
**Option Type for Functional Pattern**
func WithAccessTokenExpiry ¶
func WithAccessTokenExpiry(accessToken time.Duration) PasetoOption
WithAccessTokenExpiry sets the access token expiry for the PASETO wrapper.
func WithBasicTokenExpiry ¶
func WithBasicTokenExpiry(basicToken time.Duration) PasetoOption
WithBasicTokenExpiry sets the basic token expiry for the PASETO wrapper.
func WithExpiry ¶
func WithExpiry(accessToken, refreshToken time.Duration) PasetoOption
WithExpiry sets the access and refresh token expirations for the PASETO wrapper.
func WithIssuer ¶
func WithIssuer(issuer string) PasetoOption
WithIssuer sets the issuer for the PASETO wrapper.
func WithKeys ¶
func WithKeys(privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey) PasetoOption
WithKeys sets the private and public keys for the PASETO wrapper.
func WithPasetoMiddlewareOption ¶
func WithPasetoMiddlewareOption(opts ...PasetoMiddlewareOption) PasetoOption
WithPasetoMiddlewareOption sets the middleware options for the PASETO wrapper.
func WithPrivateKey ¶
func WithPrivateKey(privateKey ed25519.PrivateKey) PasetoOption
WithPrivateKey sets the private key for the PASETO wrapper.
func WithPublicKey ¶
func WithPublicKey(publicKey ed25519.PublicKey) PasetoOption
WithPublicKey sets the public key for the PASETO wrapper.
func WithRefreshTokenExpiry ¶
func WithRefreshTokenExpiry(refreshToken time.Duration) PasetoOption
WithRefreshTokenExpiry sets the refresh token expiry for the PASETO wrapper.
type TokenDetails ¶
type TokenDetails struct {
Token string
ExpiresAt time.Time
ID string // Unique identifier for the token
}
TokenDetails holds information about a token.
func NewTokenDetails ¶
func NewTokenDetails() *TokenDetails
type TokenValidator ¶
type TokenValidator func(claim *claims.StandardClaims, extra map[string]any) error
TokenValidator defines a function that validates claims.