From 107dd07a3539c6fe65c5a662db5b53c90e2261a0 Mon Sep 17 00:00:00 2001 From: Stian Kilaas <stinis87@gmail.com> Date: Wed, 20 Nov 2024 09:21:53 +0100 Subject: [PATCH] WP110 #1270: Removed Feide client --- .../OpenIDConnectFeideClient.php | 157 ------------------ 1 file changed, 157 deletions(-) delete mode 100644 src/Plugin/OpenIDConnectClient/OpenIDConnectFeideClient.php diff --git a/src/Plugin/OpenIDConnectClient/OpenIDConnectFeideClient.php b/src/Plugin/OpenIDConnectClient/OpenIDConnectFeideClient.php deleted file mode 100644 index d72b590..0000000 --- a/src/Plugin/OpenIDConnectClient/OpenIDConnectFeideClient.php +++ /dev/null @@ -1,157 +0,0 @@ -<?php - -namespace Drupal\uib_feide\Plugin\OpenIDConnectClient; - -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\GeneratedUrl; -use Drupal\Core\Site\Settings; -use Drupal\openid_connect\Plugin\OpenIDConnectClientBase; - -/** - * Feide OpenID Connect client. - * - * @OpenIDConnectClient( - * id = "feide", - * label = @Translation("Feide") - * ) - */ -class OpenIDConnectFeideClient extends OpenIDConnectClientBase { - - /** - * {@inheritdoc} - */ - public function defaultConfiguration(): array { - - return [ - 'issuer_url' => '', - 'authorization_endpoint' => 'https://auth.dataporten.no/oauth/authorization', - 'token_endpoint' => 'https://auth.dataporten.no/oauth/token', - 'userinfo_endpoint' => 'https://auth.dataporten.no/openid/userinfo', - 'end_session_endpoint' => '', - 'scopes' => ['openid', 'email', 'userid-feide'], - ] + parent::defaultConfiguration(); - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { - $form = parent::buildConfigurationForm($form, $form_state); - - $form['authorization_endpoint'] = [ - '#title' => $this->t('Authorization endpoint'), - '#default_value' => $this->configuration['authorization_endpoint'], - '#disabled' => TRUE, - '#type' => 'url', - ]; - $form['token_endpoint'] = [ - '#title' => $this->t('Token endpoint'), - '#default_value' => $this->configuration['token_endpoint'], - '#disabled' => TRUE, - '#type' => 'url', - ]; - $form['userinfo_endpoint'] = [ - '#title' => $this->t('UserInfo endpoint'), - '#default_value' => $this->configuration['userinfo_endpoint'], - '#disabled' => TRUE, - '#type' => 'url', - ]; - - $form['scopes'] = [ - '#title' => $this->t('Scopes'), - '#type' => 'textfield', - '#default_value' => implode(' ', $this->configuration['scopes']), - '#disabled' => TRUE, - ]; - - $form['client_id'] = [ - '#title' => $this->t('Client ID'), - '#type' => 'textfield', - '#default_value' => 'Client ID coming from .env file', - '#disabled' => TRUE, - ]; - $form['client_secret'] = [ - '#title' => $this->t('Client secret'), - '#type' => 'textfield', - '#default_value' => 'Client Secret coming from .env file', - '#disabled' => TRUE, - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { - $configuration = $form_state->getValues(); - if (!empty($configuration['scopes'])) { - $this->setConfiguration(['scopes' => explode(' ', $configuration['scopes'])]); - } - parent::submitConfigurationForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function getClientScopes(): ?array { - return $this->configuration['scopes']; - } - - /** - * {@inheritdoc} - */ - public function getEndpoints() : array { - return [ - 'authorization' => $this->configuration['authorization_endpoint'], - 'token' => $this->configuration['token_endpoint'], - 'userinfo' => $this->configuration['userinfo_endpoint'], - 'end_session' => $this->configuration['end_session_endpoint'], - ]; - } - - /** - * {@inheritdoc} - */ - protected function getRequestOptions(string $authorization_code, string $redirect_uri): array { - $client_id = Settings::get('feide_client_id'); - $client_secret = Settings::get('feide_client_secret'); - if (empty($client_id) || empty($client_secret)) { - throw new \RuntimeException('Client ID or Client Secret is not set in the .env file'); - } - - return [ - 'form_params' => [ - 'code' => $authorization_code, - 'client_id' => $client_id, - 'client_secret' => $client_secret, - 'redirect_uri' => $redirect_uri, - 'grant_type' => 'authorization_code', - ], - 'headers' => [ - 'Accept' => 'application/json', - ], - ]; - } - - /** - * {@inheritdoc} - */ - protected function getUrlOptions(string $scope, GeneratedUrl $redirect_uri): array { - $client_id = Settings::get('feide_client_id'); - if (empty($client_id)) { - throw new \RuntimeException('Client ID is not set in the .env file'); - } - - return [ - 'query' => [ - 'client_id' => $client_id, - 'response_type' => 'code', - 'scope' => $scope, - 'redirect_uri' => $redirect_uri->getGeneratedUrl(), - 'state' => $this->stateToken->generateToken(), - ], - ]; - } - -} -- GitLab