public function getUserInfoAttributes()

in modules/quanthub_core/src/UserInfoAttributesSubscriber.php [69:124]


  public function getUserInfoAttributes(ExternalAuthLoginEvent $event) {
    // Oidc plugin id is dynamic hash, we firstly get id from oidc settings.
    $generic_realms = $this->configFactory->get('oidc.settings')->get('generic_realms');
    if (count($generic_realms) == 0) {
      return;
    }
    $oidc_plugin_id = array_shift($generic_realms);
    $oidc_plugin = $this->configFactory->get('oidc.realm.quanthub_b2c_realm.' . $oidc_plugin_id);
    if (!isset($oidc_plugin)) {
      return;
    }
    $user_attributes_endpoint = $oidc_plugin->get(self::USER_ATTRIBUTES_ENDPOINT);

    $token = $this->openidConnectSession->getJsonWebTokens()->getAccessToken()->getValue();

    try {
      $response = $this->httpClient->get($user_attributes_endpoint, [
        'headers' => [
          'Authorization' => 'Bearer ' . $token,
          'Content-Type' => 'application/json',
        ],
      ]);

      $user_attributes_data = json_decode($response->getBody(), TRUE);

      $this->userData->set(
        self::MODULE_NAME,
        $event->getAccount()->id(),
        self::USER_QUANTHUB_ID,
        array_shift($user_attributes_data['userAttributes']['USER_ID'])
      );

      $this->userData->set(
        self::MODULE_NAME,
        $event->getAccount()->id(),
        self::USER_QUANTHUB_ROLE,
        $user_attributes_data['userAttributes']['USER_ROLE']
      );

      $this->userData->set(
        self::MODULE_NAME,
        $event->getAccount()->id(),
        self::USER_QUANTHUB_GROUPS,
        $user_attributes_data['userAttributes']['USER_GROUPS']
      );

      // @todo perhaps need to save USER_ORGANIZATION too.
    }
    catch (RequestException $e) {
      $this->logger->error('Failed to retrieve quanthub user id for anonymous user: @error.', [
        '@error' => $e->getMessage(),
      ]);

      throw new \RuntimeException('Failed to retrieve quanthub user id for anonymous token', 0, $e);
    }
  }