scope and claims not working as expected

Created on 22 March 2022, over 2 years ago
Updated 7 March 2024, 4 months ago

Problem/Motivation

I can't get scope to send back the claims properly. No matter what scope is sent, it seems like \Drupal\oauth2_server\OAuth2Storage::getUserClaims is never called.

I noticed the code for invoking the hooks was recently committed.

Is scope still wip?

Thank you.

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States shadcn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡­Switzerland dpacassi ZΓΌrich, Switzerland

    We ran in the same issue, following code should work with the current state on dev:

    /**
     * Implements hook_oauth2_server_user_claims_alter().
     *
     * @param array $claims
     *   An array of claims.
     * @param \Drupal\user\UserInterface $account
     *   A user account object.
     * @param array $requested_scopes
     *   An array of requested scopes.
     */
    function your_module_oauth2_server_user_claims_alter(array &$claims, \Drupal\user\UserInterface $account, array $requested_scopes) {
      if (in_array('openid', $requested_scopes)) {
        $claims['zipcode'] = $account->get('field_zip')->value;
        $claims['town'] = $account->get('field_city')->value;
        $claims['country'] = $account->get('field_country')->value;
        // etc.
      }
    }
    
  • πŸ‡¦πŸ‡ΊAustralia cafuego

    Nice, that does the trick. Thank you :-)

  • Status changed to Closed: outdated 4 months ago
  • πŸ‡¦πŸ‡ΊAustralia cafuego
Production build 0.69.0 2024