mirror of
https://forgejo.merr.is/annika/jwtauth.git
synced 2025-12-13 15:09:59 -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"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -191,11 +192,14 @@ func FromContext(ctx context.Context) (*jwt.Token, Claims, error) {
|
||||||
|
|
||||||
var claims Claims
|
var claims Claims
|
||||||
if token != nil {
|
if token != nil {
|
||||||
tokenClaims, ok := token.Claims.(jwt.MapClaims)
|
switch tokenClaims := token.Claims.(type) {
|
||||||
if !ok {
|
case Claims:
|
||||||
panic("jwtauth: expecting jwt.MapClaims")
|
// Nop.
|
||||||
}
|
case jwt.MapClaims:
|
||||||
claims = Claims(tokenClaims)
|
claims = Claims(tokenClaims)
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("jwtauth: unknown type of Claims: %T", token.Claims))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
claims = Claims{}
|
claims = Claims{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue