Documentation ¶
Index ¶
- Variables
- func LoadEd25519Key(ed25519PublicKey, ed25519PrivateKey string) (ed25519.PublicKey, ed25519.PrivateKey, error)
- func ParseEdPrivateKeyBlock(key []byte) (ed25519.PrivateKey, error)
- func ParseEdPublicKeyBlock(key []byte) (ed25519.PublicKey, error)
- type Claims
- type ClaimsOption
- type Maker
- type PasetoLocalMaker
- func (maker *PasetoLocalMaker) CreateToken(claims *Claims) (string, error)
- func (maker *PasetoLocalMaker) RefreshToken(claims *Claims, duration time.Duration) (string, error)
- func (maker *PasetoLocalMaker) RevokeToken(claims *Claims) error
- func (maker *PasetoLocalMaker) VerifyToken(token string) (*Claims, error)
- type PasetoMiddleware
- func (pm *PasetoMiddleware) Authorization() gin.HandlerFunc
- func (pm *PasetoMiddleware) Init(maker Maker)
- func (pm *PasetoMiddleware) LogOut() gin.HandlerFunc
- func (pm *PasetoMiddleware) LoginHandler(loginFunc func(c *gin.Context) (data any, err error)) gin.HandlerFunc
- func (pm *PasetoMiddleware) RefreshToken() gin.HandlerFunc
- type PasetoPublicMaker
- func (maker *PasetoPublicMaker) CreateToken(claims *Claims) (string, error)
- func (maker *PasetoPublicMaker) RefreshToken(claims *Claims, duration time.Duration) (string, error)
- func (maker *PasetoPublicMaker) RevokeToken(claims *Claims) error
- func (maker *PasetoPublicMaker) VerifyToken(token string) (*Claims, error)
- type Response
- type TokenResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrTokenExpired = errors.New("token has expired") ErrTokenMaxRefresh = errors.New("token is expired max refresh time") )
View Source
var ( ErrNoAuthorizationHeader = errors.New("no Authorization header or the Authorization header is empty") ErrAuthorizationHeaderFormat = errors.New("incorrectly formatted Authorization header") ErrNoAuthorizationCookieSet = errors.New("no Authorization Cookie set or cookie value is empty") )
View Source
var ( ErrNotEdPrivateKey = errors.New("key is not a valid Ed25519 private key") ErrNotEdPublicKey = errors.New("key is not a valid Ed25519 public key") )
Functions ¶
func LoadEd25519Key ¶
func LoadEd25519Key(ed25519PublicKey, ed25519PrivateKey string) (ed25519.PublicKey, ed25519.PrivateKey, error)
LoadEd25519Key Load Edwards curve key-pair from key block string
func ParseEdPrivateKeyBlock ¶
func ParseEdPrivateKeyBlock(key []byte) (ed25519.PrivateKey, error)
ParseEdPrivateKeyBlock parses a pem.Block.Bytes Edwards curve private key
Types ¶
type Claims ¶
type Claims struct { Issuer string `json:"issuer,omitempty"` Subject string `json:"subject,omitempty"` Audience string `json:"audience,omitempty"` IssuedAt time.Time `json:"issued_at"` ExpiredAt time.Time `json:"expired_at"` MaxRefreshAt time.Time `json:"max_refresh_at"` Data any `json:"data"` }
type ClaimsOption ¶
type ClaimsOption = func(c *Claims)
func WithClaimsOption ¶
func WithClaimsOption(issuer, subject, audience string) ClaimsOption
WithClaimsOption options with issuer, subject audience
type Maker ¶
type Maker interface { // CreateToken create a new token for authentication data and time duration CreateToken(claims *Claims) (token string, err error) // VerifyToken check if the token is verified or not VerifyToken(token string) (*Claims, error) // RefreshToken refresh token on Claims.MaxRefreshAt before RefreshToken(claims *Claims, duration time.Duration) (token string, err error) // RevokeToken expire the token RevokeToken(claims *Claims) error }
func NewPasetoLocalMaker ¶
NewPasetoLocalMaker create paseto maker from ed25519 key
func NewPasetoPublicMaker ¶
NewPasetoPublicMaker create paseto maker from ed25519 key
type PasetoLocalMaker ¶
type PasetoLocalMaker struct {
// contains filtered or unexported fields
}
func (*PasetoLocalMaker) CreateToken ¶
func (maker *PasetoLocalMaker) CreateToken(claims *Claims) (string, error)
func (*PasetoLocalMaker) RefreshToken ¶
func (*PasetoLocalMaker) RevokeToken ¶
func (maker *PasetoLocalMaker) RevokeToken(claims *Claims) error
func (*PasetoLocalMaker) VerifyToken ¶
func (maker *PasetoLocalMaker) VerifyToken(token string) (*Claims, error)
type PasetoMiddleware ¶
type PasetoMiddleware struct { Issuer string `json:"issuer,omitempty"` Subject string `json:"subject,omitempty"` Audience string `json:"audience,omitempty"` Maker Maker Claims *Claims Expired time.Duration MaxRefresh time.Duration RefreshTokenURL string BaseLoginURL string LogoutURL string TokenHeadName string TokenLookup map[string]string CookieName string CookieSameSite http.SameSite SendCookie bool SecureCookie bool CookieHTTPOnly bool }
func (*PasetoMiddleware) Authorization ¶
func (pm *PasetoMiddleware) Authorization() gin.HandlerFunc
Authorization gin authorization middleware handler
func (*PasetoMiddleware) Init ¶
func (pm *PasetoMiddleware) Init(maker Maker)
Init parse PasetoMiddleware attributes to claims
func (*PasetoMiddleware) LogOut ¶
func (pm *PasetoMiddleware) LogOut() gin.HandlerFunc
func (*PasetoMiddleware) LoginHandler ¶
func (pm *PasetoMiddleware) LoginHandler(loginFunc func(c *gin.Context) (data any, err error)) gin.HandlerFunc
LoginHandler from gin context get login data to claim create token
func (*PasetoMiddleware) RefreshToken ¶
func (pm *PasetoMiddleware) RefreshToken() gin.HandlerFunc
RefreshToken refresh token before max refresh time
type PasetoPublicMaker ¶
type PasetoPublicMaker struct {
// contains filtered or unexported fields
}
func (*PasetoPublicMaker) CreateToken ¶
func (maker *PasetoPublicMaker) CreateToken(claims *Claims) (string, error)
func (*PasetoPublicMaker) RefreshToken ¶
func (*PasetoPublicMaker) RevokeToken ¶
func (maker *PasetoPublicMaker) RevokeToken(claims *Claims) error
func (*PasetoPublicMaker) VerifyToken ¶
func (maker *PasetoPublicMaker) VerifyToken(token string) (*Claims, error)
type TokenResponse ¶
Click to show internal directories.
Click to hide internal directories.