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 #1

Merged
merged 1 commit into from
Sep 11, 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
8 changes: 4 additions & 4 deletions claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ func validateBoundClaims(logger log.Logger, boundClaims, allClaims map[string]in
switch v := actValue.(type) {
case []interface{}:
actVals = v
case string:
case string, bool:
actVals = []interface{}{v}
default:
return fmt.Errorf("received claim is not a string or list: %v", actValue)
return fmt.Errorf("received claim is not a string, boolean or list: %v", actValue)
}

switch v := expValue.(type) {
case []interface{}:
expVals = v
case string:
case string, bool:
expVals = []interface{}{v}
default:
return fmt.Errorf("bound claim is not a string or list: %v", expValue)
return fmt.Errorf("bound claim is not a string, boolean or list: %v", expValue)
}

found := false
Expand Down
21 changes: 21 additions & 0 deletions claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,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 @@ -359,6 +369,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