Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions os2forms_nemlogin_openid_connect.module
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use Drupal\os2forms_nemlogin_openid_connect\Helper\Settings;
use Drupal\os2forms_nemlogin_openid_connect\Helper\WebformHelper;
use Drupal\webform\WebformSubmissionInterface;


/**
* Implements hook_help().
*/
Expand Down Expand Up @@ -67,6 +68,11 @@ function os2forms_nemlogin_openid_connect_theme(array $existing, string $type, s
'query' => NULL,
],
],
'os2forms-nemlogin-openid-connect-intermediary-info-page' => [
'variables' => [
'redirect_url' => NULL,
],
],
];
}

Expand Down
10 changes: 10 additions & 0 deletions os2forms_nemlogin_openid_connect.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ os2forms_nemlogin_openid_connect.admin.settings:
_title: 'OS2Forms NemLogin OpenID Connect settings'
requirements:
_permission: 'administer site configuration'

os2forms_nemlogin_openid_connect.info_page:
path: '/info-page'
defaults:
_controller: 'Drupal\os2forms_nemlogin_openid_connect\Controller\OpenIDConnectController::infoPage'
requirements:
# Anonymous users must be able to access this route.
_access: 'TRUE'
options:
no_cache: 'TRUE'
19 changes: 19 additions & 0 deletions src/Controller/OpenIDConnectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
Expand Down Expand Up @@ -83,6 +84,24 @@ public function __construct(
$this->setLogger($logger);
}

public function infoPage(): array {
$request = $this->requestStack->getCurrentRequest();
$pluginId = $request->query->get('id');

$redirect_url = Url::fromRoute('os2forms_nemlogin_openid_connect.openid_connect_authenticate', [
'id' => $pluginId,
OpenIDConnectController::QUERY_LOCATION_NAME => $request->getRequestUri(),
])
->toString(TRUE)
->getGeneratedUrl();

// Render the template.
return [
'#theme' => 'os2forms-nemlogin-openid-connect-intermediary-info-page',
'#redirect_url' => $redirect_url,
];
}

/**
* {@inheritdoc}
*/
Expand Down
33 changes: 25 additions & 8 deletions src/Plugin/os2web/NemloginAuthProvider/OpenIDConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* )
*/
class OpenIDConnect extends AuthProviderBase {

use LoggerTrait;
use LoggerAwareTrait;

Expand All @@ -37,6 +38,10 @@ class OpenIDConnect extends AuthProviderBase {
*/
private const SESSION_TOKEN = 'os2forms_nemlogin_openid_connect.user_token';

/**
* Plugin id for AD login
*/
private const OPENIDCONNECT_AD = 'openid_connect_ad';
/**
* Fetch only mode flag.
*
Expand Down Expand Up @@ -96,7 +101,8 @@ public function __construct(
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
// Shamelessly lifted from Drupal\os2web_nemlogin\Plugin\AuthProviderBase.
// Swapping config with a values from config object.
$configObject = $container->get('config.factory')->get(AuthProviderBaseSettingsForm::$configName);
$configObject = $container->get('config.factory')
->get(AuthProviderBaseSettingsForm::$configName);
if ($configurationSerialized = $configObject->get($plugin_id)) {
$configuration = unserialize($configurationSerialized, ['allowed_classes' => FALSE]);
}
Expand Down Expand Up @@ -169,6 +175,17 @@ public function isAuthenticatedCompany() {
public function login() {
$request = $this->requestStack->getCurrentRequest();

// If form requires AD-login, show info-page regarding AD-roles.
if (self::OPENIDCONNECT_AD === $this->getPluginId()) {
$info_page_url = Url::fromRoute('os2forms_nemlogin_openid_connect.info_page', [
'id' => $this->getPluginId(),
])
->toString(TRUE)
->getGeneratedUrl();

return (new LocalRedirectResponse($info_page_url))->send();
}

$token = $this->getToken();
if (NULL === $token) {
// Pass the current request uri on to the controller to tell it where to
Expand Down Expand Up @@ -275,13 +292,13 @@ public function fetchValue($key) {
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'nemlogin_openid_connect_discovery_url' => '',
'nemlogin_openid_connect_client_id' => '',
'nemlogin_openid_connect_client_secret' => '',
'nemlogin_openid_connect_fetch_once' => '',
'nemlogin_openid_connect_post_logout_redirect_uri' => '',
'nemlogin_openid_connect_user_claims' => '',
];
'nemlogin_openid_connect_discovery_url' => '',
'nemlogin_openid_connect_client_id' => '',
'nemlogin_openid_connect_client_secret' => '',
'nemlogin_openid_connect_fetch_once' => '',
'nemlogin_openid_connect_post_logout_redirect_uri' => '',
'nemlogin_openid_connect_user_claims' => '',
];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Velkommen!</h1>
<a href="{{ redirect_url }}">Fortsæt med AD login</a>