Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for boolean values in bound claims #73

Merged
merged 2 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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