Skip to content

Commit

Permalink
Add UnmarshalJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak committed Sep 17, 2019
1 parent 20c5c52 commit 7c4b0a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion basculehttp/tokenFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (btf BearerTokenFactory) ParseAndValidate(ctx context.Context, _ *http.Requ

principal, ok := payload[jwtPrincipalKey].(string)
if !ok {
return nil, emperror.WrapWith(ErrorUnexpectedPrincipal, "failed to get and convert principal", "principal", payload[jwtPrincipalKey], "payload", payload)
return nil, emperror.WrapWith(ErrorUnexpectedPrincipal, "failed to get and convert principal", "principal", payload[jwtPrincipalKey], "claims map", claimsMap, "payload", payload)
}

return bascule.NewToken("jwt", principal, payload), nil
Expand Down
6 changes: 6 additions & 0 deletions jws.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bascule

import (
"encoding/json"
"errors"

jwt "github.com/dgrijalva/jwt-go"
Expand Down Expand Up @@ -66,6 +67,11 @@ func (c *ClaimsWithLeeway) Valid() error {
return vErr
}

func (c *ClaimsWithLeeway) UnmarshalJSON(data []byte) error {
c.MapClaims = make(jwt.MapClaims) // just to be sure it's clean before each unmarshal
return json.Unmarshal(data, &c.MapClaims)
}

// GetMap returns a map of string to interfaces of the values in the ClaimsWithLeeway
func (c *ClaimsWithLeeway) GetMap() (map[string]interface{}, error) {
// for StandardClaims, which don't work with the []string aud values that we use
Expand Down

0 comments on commit 7c4b0a6

Please sign in to comment.