Skip to content

Commit

Permalink
Supporting email and phone scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
slogan-15 committed Dec 3, 2024
1 parent a65653b commit 37e73c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Http/Handlers/ConfigurationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function configuration(): array {
'authorization_endpoint' => Router::make_rest_url( 'authorize' ),
'token_endpoint' => Router::make_rest_url( 'token' ),
'userinfo_endpoint' => Router::make_rest_url( 'userinfo' ),
'scopes_supported' => array( 'openid', 'profile' ),
'scopes_supported' => array( 'openid', 'profile', 'email', 'phone' ),
'response_types_supported' => array( 'code' ),
'id_token_signing_alg_values_supported' => array( 'RS256' ),
);
Expand Down
15 changes: 14 additions & 1 deletion src/Storage/UserClaimsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,26 @@ public function getUserClaims( $user_id, $scope ) {
'nickname' => 'user_nicename',
);

// Is email scope requested?
if(in_array('email', $scopes, true)) {
$field_map['email'] = 'user_email';
}

// Is phone scope requested?
if(in_array('phone', $scopes, true)) {
$field_map['phone'] = 'user_phone';
}

foreach ( $field_map as $key => $value ) {
if ( $user->$value ) {
$claims[ $key ] = $user->$value;
}
}

$claims['picture'] = get_avatar_url( $user->user_email );
// Is profile scope requested, add picture (user avatar)?
if(in_array( 'profile', $scopes, true )) {
$claims['picture'] = get_avatar_url( $user->user_email );
}

return apply_filters( 'oidc_user_claims', $claims, $user );
}
Expand Down

0 comments on commit 37e73c8

Please sign in to comment.