getClientId(); $options['client_secret'] = $this->getClientSecret(); } $options['access_token_url'] = $this->getUrl('token/'); $options['authorization_url'] = $this->getUrl('authorization/'); $options['infos_url'] = $this->getUrl('userinfo/'); parent::__construct($httpClient, $httpUtils, $options, $name, $storage); } protected function getUrl($path): string { if (isDevelopment()) { return self::SANDBOX_URL.$path; } return self::PROD_URL.$path; } protected function getClientId() { if (isLocalDevelopment()) { return $this->options['client_id']; } $settings = \Settings::getDefault(); return $settings['oauth']['mojeid']['client_id'] ?? ''; } protected function getClientSecret() { if (isLocalDevelopment()) { return $this->options['client_secret']; } $settings = \Settings::getDefault(); return $settings['oauth']['mojeid']['client_secret'] ?? ''; } protected function doGetTokenRequest($url, array $parameters = []) { $parameters['client_id'] = $this->getClientId(); $parameters['client_secret'] = $this->getClientSecret(); return $this->httpRequest($url, http_build_query($parameters, '', '&')); } public function getAuthorizationUrl($redirectUri, array $extraParameters = []) { return parent::getAuthorizationUrl($redirectUri, [ 'claims' => json_encode([ 'id_token' => [ 'birthdate' => [ 'essential' => true, ], 'name' => [ 'essential' => true, ], 'given_name' => [ 'essential' => true, ], 'family_name' => [ 'essential' => true, ], 'email' => [ 'essential' => true, ], 'address' => [ 'essential' => false, ], 'mojeid_valid' => ['essential' => true], ], ]), ]); } public function updateUserData(\User $user, UserResponseInterface $response) { $data = []; if ($birthdate = $response->getBirthdate()) { $data['birthdate'] = $birthdate; } if ($name = $response->getFirstName()) { $data['name'] = $name; } if ($surname = $response->getLastName()) { $data['surname'] = $surname; } if ($address = $response->getAddress()) { $data['street'] = $address['street_address'] ?? ''; $data['city'] = $address['locality'] ?? ''; $data['zip'] = $address['postal_code'] ?? ''; $data['country'] = $address['country'] ?? ''; } if (!empty($data)) { sqlQueryBuilder()->update('users') ->directValues($data) ->where(Operator::equals(['id' => $user->id])) ->execute(); } if ($birthdate) { $date = \DateTime::createFromFormat('Y-m-d', $birthdate)->add(\DateInterval::createFromDateString('+18YEARS')); $this->ageVerifyUtil?->setVerificationData(legalAge: $date <= (new \DateTime()) ? 'Y' : 'N', type: 'mojeid', userId: $user->id); } } #[Required] public function setAgeVerifyUtil(?AgeVerifyUtil $ageVerifyUtil): void { $this->ageVerifyUtil = $ageVerifyUtil; } }