Documentation ¶
Index ¶
- func ExtractPayload(c *gin.Context) map[string]interface{}
- type GinMiddleware
- func (m *GinMiddleware) Init() error
- func (m *GinMiddleware) IssueAccessToken(refreshToken string, payload map[string]interface{}, c *gin.Context)
- func (m *GinMiddleware) LoginHandler(c *gin.Context)
- func (m *GinMiddleware) LogoutHandler(c *gin.Context)
- func (m *GinMiddleware) MiddlewareFunc() gin.HandlerFunc
- func (m *GinMiddleware) RefreshHandler(c *gin.Context)
- type IRefreshTokenStorage
- type Login
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPayload ¶
Helper: Extract payload from gic.Context
Types ¶
type GinMiddleware ¶
type GinMiddleware struct { // secret key SecretKey string // header name in request that contains our token Header string // algorithm (see github.com/robbert229/jwt for details) Algorithm *jwt.Algorithm // access token ttl Timeout time.Duration // refresh token ttl RefreshTimeout time.Duration Unauthorized func(*gin.Context, int, string) // authentication function Authenticator func(userID string, password string, c *gin.Context) (interface{}, bool) // authorization function Authorizator func(payload interface{}, c *gin.Context) bool // refresh token storage instance RefreshTokenStorage IRefreshTokenStorage }
func (*GinMiddleware) IssueAccessToken ¶
func (m *GinMiddleware) IssueAccessToken(refreshToken string, payload map[string]interface{}, c *gin.Context)
Generate new access token and send it to client
func (*GinMiddleware) LoginHandler ¶
func (m *GinMiddleware) LoginHandler(c *gin.Context)
Handler for login action
func (*GinMiddleware) LogoutHandler ¶
func (m *GinMiddleware) LogoutHandler(c *gin.Context)
Handler for logout action
func (*GinMiddleware) MiddlewareFunc ¶
func (m *GinMiddleware) MiddlewareFunc() gin.HandlerFunc
MiddlewareFunc makes GinMiddleware implement the Gin Middleware interface.
func (*GinMiddleware) RefreshHandler ¶
func (m *GinMiddleware) RefreshHandler(c *gin.Context)
Handler for token refresh action
type IRefreshTokenStorage ¶
type IRefreshTokenStorage interface { Issue() (string, error) // Call to check is refresh token already expired IsExpired(token string) bool // Add/Update refresh token in Update(token string, timeout time.Duration, payload map[string]interface{}, c *gin.Context) error // Delete refresh token from storage Delete(token string) error // Revoke refresh token Revoke(token string, accessTokenTimeout time.Duration) error // Check is token was revoked IsRevoked(token string) bool }
Refresh token storage interface
Click to show internal directories.
Click to hide internal directories.