Skip to content

Commit

Permalink
Support jwtauth.Claims in FromContext(), fixes panic (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek authored and pkieltyka committed Jan 18, 2018
1 parent 5d94d7c commit fdeab96
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jwtauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -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{}
}
Expand Down

0 comments on commit fdeab96

Please sign in to comment.