Skip to content
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
2 changes: 1 addition & 1 deletion includes/openid-connect-generic-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ public function validate_user_claim( $user_claim, $id_token_claim ) {
}

// Make sure the id_token sub equals the user_claim sub, according to spec.
if ( $id_token_claim['sub'] !== $user_claim['sub'] ) {
if ( strval( $id_token_claim['sub'] ) !== strval( $user_claim['sub'] ) ) {
return new WP_Error( 'incorrect-user-claim', __( 'Incorrect user claim.', 'daggerhart-openid-connect-generic' ), func_get_args() );
}

Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/includes/openid-connect-generic-client_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ public function test_validate_id_token_claim_with_explicit_issuer() {
$this->assertTrue( $result );
}

/**
* Test validate_user_claim accepts an integer userinfo sub equal to the id_token sub.
*
* @group ClientTests
*/
public function test_validate_user_claim_with_integer_sub() {
$client = $this->create_client();

$this->assertTrue( $client->validate_user_claim( array( 'sub' => 35 ), array( 'sub' => '35' ) ) );

$result = $client->validate_user_claim( array( 'sub' => 36 ), array( 'sub' => '35' ) );
$this->assertWPError( $result );
$this->assertSame( 'incorrect-user-claim', $result->get_error_code() );
}

/**
* Helper to create client instance for testing.
*
Expand Down
Loading