mirror of
https://forgejo.merr.is/annika/jwtauth.git
synced 2025-12-11 12:13:14 -05:00
Support jwtauth.Claims in FromContext(), fixes panic (#25)
This commit is contained in:
parent
5d94d7c263
commit
fdeab96f74
1 changed files with 8 additions and 4 deletions
12
jwtauth.go
12
jwtauth.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -191,11 +192,14 @@ func FromContext(ctx context.Context) (*jwt.Token, Claims, error) {
|
|||
|
||||
var claims Claims
|
||||
if token != nil {
|
||||
tokenClaims, ok := token.Claims.(jwt.MapClaims)
|
||||
if !ok {
|
||||
panic("jwtauth: expecting jwt.MapClaims")
|
||||
switch tokenClaims := token.Claims.(type) {
|
||||
case Claims:
|
||||
// Nop.
|
||||
case jwt.MapClaims:
|
||||
claims = Claims(tokenClaims)
|
||||
default:
|
||||
panic(fmt.Sprintf("jwtauth: unknown type of Claims: %T", token.Claims))
|
||||
}
|
||||
claims = Claims(tokenClaims)
|
||||
} else {
|
||||
claims = Claims{}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue