Skip to content

Commit

Permalink
Add support for boolean values in bound claims (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogan7n authored and Jim Kalafut committed Oct 10, 2019
1 parent fa5d6cc commit 6e442bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func validateBoundClaims(logger log.Logger, boundClaims, allClaims map[string]in
return nil
}

// normalizeList takes a string or list and returns a list. This is useful when
// normalizeList takes a string, bool or list and returns a list. This is useful when
// providers are expected to return a list (typically of strings) but reduce it
// to a string type when the list count is 1.
func normalizeList(raw interface{}) ([]interface{}, bool) {
Expand All @@ -137,7 +137,7 @@ func normalizeList(raw interface{}) ([]interface{}, bool) {
switch v := raw.(type) {
case []interface{}:
normalized = v
case string:
case string, bool:
normalized = []interface{}{v}
default:
return nil, false
Expand Down
21 changes: 21 additions & 0 deletions claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ func TestValidateBoundClaims(t *testing.T) {
},
errExpected: false,
},
{
name: "valid - boolean claim",
boundClaims: map[string]interface{}{
"email_verified": []interface{}{false},
},
allClaims: map[string]interface{}{
"email_verified": []interface{}{false},
},
errExpected: false,
},
{
name: "valid - match within list",
boundClaims: map[string]interface{}{
Expand Down Expand Up @@ -360,6 +370,17 @@ func TestValidateBoundClaims(t *testing.T) {
},
errExpected: true,
},
{
name: "invalid bound claim expected boolean value",
boundClaims: map[string]interface{}{
"email_verified": true,
},
allClaims: map[string]interface{}{
"email_verified": "true",
},
errExpected: true,
},

{
name: "invalid received claim expected value",
boundClaims: map[string]interface{}{
Expand Down

0 comments on commit 6e442bc

Please sign in to comment.