Skip to content

Commit

Permalink
feat: Post login Idp
Browse files Browse the repository at this point in the history
Signed-off-by: Hoang Pham <[email protected]>
  • Loading branch information
hweihwang committed Jul 8, 2024
1 parent e8c669b commit cac3ce5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/Controller/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ public function login(int $idp = 1): Http\RedirectResponse|Http\TemplateResponse
$ssoUrl = $auth->login($returnUrl, [], false, false, true);

$settings = $this->samlSettings->get($idp);
$method = $settings['general-saml_request_method'] ?? 'get';
if ($method === 'post') {
$isSAMLRequestUsingPost = isset($settings['general-is_saml_request_using_post']) && $settings['general-is_saml_request_using_post'] === '1';
if ($isSAMLRequestUsingPost) {
$query = parse_url($ssoUrl, PHP_URL_QUERY);
parse_str($query, $params);

Expand Down Expand Up @@ -649,7 +649,7 @@ private function getSSOUrl(string $redirectUrl, string $idp): string {
$csrfToken = $csrfTokenManager->getToken();

$settings = $this->samlSettings->get((int)$idp);
$method = $settings['general-saml_request_method'] ?? 'get';
$method = $settings['general-is_saml_request_using_post'] ?? 'get';

return $this->urlGenerator->linkToRouteAbsolute(
'user_saml.SAML.login',
Expand Down
1 change: 1 addition & 0 deletions lib/SAMLSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SAMLSettings {
public const IDP_CONFIG_KEYS = [
'general-idp0_display_name',
'general-uid_mapping',
'general-is_saml_request_using_post',
'general-saml_request_method',
'idp-entityId',
'idp-singleLogoutService.responseUrl',
Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function getForm() {
'type' => 'line',
'required' => false,
];
$generalSettings['saml_request_method'] = [
$generalSettings['is_saml_request_using_post'] = [
'text' => $this->l10n->t('Use POST method for SAML request (default: GET)'),
'type' => 'checkbox',
'required' => false,
Expand Down
2 changes: 1 addition & 1 deletion templates/login_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<input type="hidden" name="Signature" value="<?= $_['signature'] ?>" />
<noscript>
<p>
<?php p($l->t('Please wait while you are redirected to the SSO server.')); ?>
<?php p($l->t('JavaScript is disabled in your browser. Please enable it to continue.')) ?>
</p>
<input type="submit" value="Continue" />
</noscript>
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function formDataProvider() {
'type' => 'line',
'required' => false,
],
'saml_request_method' => [
'is_saml_request_using_post' => [
'text' => $this->l10n->t('Use POST method for SAML request (default: GET)'),
'type' => 'checkbox',
'required' => false,
Expand Down Expand Up @@ -231,7 +231,7 @@ public function testGetFormWithoutType() {
->willReturn('');

$params = $this->formDataProvider();
unset($params['general']['idp0_display_name'], $params['general']['saml_request_method'], $params['general']['allow_multiple_user_back_ends']);
unset($params['general']['idp0_display_name'], $params['general']['is_saml_request_using_post'], $params['general']['allow_multiple_user_back_ends']);
$params['type'] = '';

$expected = new TemplateResponse('user_saml', 'admin', $params);
Expand Down

0 comments on commit cac3ce5

Please sign in to comment.