Support jwtauth.Claims in FromContext(), fixes panic (#25)

This commit is contained in:
Vojtech Vitek 2018-01-17 22:14:14 -05:00 committed by Peter Kieltyka
parent 5d94d7c263
commit fdeab96f74

View file

@ -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)
default:
panic(fmt.Sprintf("jwtauth: unknown type of Claims: %T", token.Claims))
} }
claims = Claims(tokenClaims)
} else { } else {
claims = Claims{} claims = Claims{}
} }