mirror of
https://forgejo.merr.is/annika/jwtauth.git
synced 2025-12-11 13:47:41 -05:00
Keep jwt.Token.Claims as a jwt.MapClaims type
This commit is contained in:
parent
6444fb9aef
commit
287076f82d
1 changed files with 9 additions and 7 deletions
16
jwtauth.go
16
jwtauth.go
|
|
@ -165,11 +165,6 @@ func (ja *JwtAuth) Decode(tokenString string) (t *jwt.Token, err error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Wrap type to jwtauth.Claims
|
||||
claims := Claims(t.Claims.(jwt.MapClaims))
|
||||
t.Claims = claims
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +210,11 @@ func FromContext(ctx context.Context) (*jwt.Token, Claims, error) {
|
|||
|
||||
var claims Claims
|
||||
if token != nil {
|
||||
claims, _ = token.Claims.(Claims)
|
||||
tokenClaims, ok := token.Claims.(jwt.MapClaims)
|
||||
if !ok {
|
||||
panic("jwtauth: expecting jwt.MapClaims")
|
||||
}
|
||||
claims = Claims(tokenClaims)
|
||||
} else {
|
||||
claims = Claims{}
|
||||
}
|
||||
|
|
@ -226,7 +225,10 @@ func FromContext(ctx context.Context) (*jwt.Token, Claims, error) {
|
|||
}
|
||||
|
||||
func IsExpired(t *jwt.Token) bool {
|
||||
claims := t.Claims.(Claims)
|
||||
claims, ok := t.Claims.(jwt.MapClaims)
|
||||
if !ok {
|
||||
panic("jwtauth: expecting jwt.MapClaims")
|
||||
}
|
||||
|
||||
if expv, ok := claims["exp"]; ok {
|
||||
var exp int64
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue