From d13c9ae11cd8e21d2fe26f3884884b72a61489f2 Mon Sep 17 00:00:00 2001 From: Pietro Saccardi Date: Mon, 20 Mar 2023 17:30:40 +0100 Subject: [PATCH 1/3] Handle the state parameter in callback URL. This fixes login with certain providers, e.g. Authentik, that trigger the message "OAuth: State not found in session, are you sure you stored it?" This closes #6. --- Generic.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Generic.php b/Generic.php index 706bdda..6b1e342 100644 --- a/Generic.php +++ b/Generic.php @@ -10,6 +10,10 @@ */ class Generic extends AbstractOAuth2Base { + /** @inheritdoc */ + public function needsStateParameterInAuthUrl() { + return true; + } /** @inheritdoc */ public function getAuthorizationEndpoint() From 51298b298fbac4a06fe6f3b035130f21c919c74a Mon Sep 17 00:00:00 2001 From: Pietro Saccardi Date: Tue, 21 Mar 2023 14:09:40 +0100 Subject: [PATCH 2/3] Toggle state parm depending on config parm --- Generic.php | 3 ++- conf/default.php | 1 + conf/metadata.php | 1 + lang/cs/settings.php | 2 +- lang/en/settings.php | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Generic.php b/Generic.php index 6b1e342..fb0ef76 100644 --- a/Generic.php +++ b/Generic.php @@ -12,7 +12,8 @@ class Generic extends AbstractOAuth2Base { /** @inheritdoc */ public function needsStateParameterInAuthUrl() { - return true; + $plugin = plugin_load('helper', 'oauthgeneric'); + return 0 !== $plugin->getConf('needs-state'); } /** @inheritdoc */ diff --git a/conf/default.php b/conf/default.php index b827871..4682615 100644 --- a/conf/default.php +++ b/conf/default.php @@ -11,6 +11,7 @@ $conf['userurl'] = ''; $conf['authmethod'] = 0; $conf['scopes'] = ''; +$conf['needs-state'] = 0; $conf['json-user'] = ''; $conf['json-name'] = ''; diff --git a/conf/metadata.php b/conf/metadata.php index 59cac6e..c227540 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -11,6 +11,7 @@ $meta['userurl'] = array('string'); $meta['authmethod'] = array('multichoice', '_choices' => [0, 1, 6, 2, 3, 4, 5]); $meta['scopes'] = array('array'); +$meta['needs-state'] = array('onoff'); $meta['json-user'] = array('string'); $meta['json-name'] = array('string'); diff --git a/lang/cs/settings.php b/lang/cs/settings.php index e5f5510..bc8adb9 100644 --- a/lang/cs/settings.php +++ b/lang/cs/settings.php @@ -11,8 +11,8 @@ $lang['tokenurl'] = 'URL pro získání tokenu'; $lang['userurl'] = 'Relativní URL pro získání uživatelských informací z API (musí vracet JSON data autentizovaného uživatele)'; $lang['authmethod'] = 'Autorizační metoda pro získání uživatelských informací z API'; -$lang['scopes'] = 'Scopes to request (comma separated)'; $lang['scopes'] = 'Požadovaná oprávnění (scopes, oddělená čárkou)'; +$lang['needs-state'] = 'Whether the provider needs and supplies a state parameter in the callback URL.'; $lang['json-user'] = 'Objektová cesta k uživatelskému jménu (tečková notace)'; $lang['json-name'] = 'Objektová cesta k celému jménu uživatele (tečkovánotace)'; diff --git a/lang/en/settings.php b/lang/en/settings.php index 12e3dd8..33ef4d6 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -12,6 +12,7 @@ $lang['userurl'] = 'URL to the user info API endpoint (must return JSON about the authenticated user)'; $lang['authmethod'] = 'Authorization method used when talking to the user API'; $lang['scopes'] = 'Scopes to request (comma separated)'; +$lang['needs-state'] = 'The provider needs and supplies a state parameter in the callback URL.'; $lang['json-user'] = 'Access to the username in dot notation'; $lang['json-name'] = 'Access to the full name in dot notation'; From 82cf301d14b276b392c7a672e550f4f8c942a1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Matu=C5=A1kov=C3=A1?= Date: Tue, 21 Mar 2023 23:47:36 +0100 Subject: [PATCH 3/3] Localize new setting in Czech --- lang/cs/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cs/settings.php b/lang/cs/settings.php index bc8adb9..cea5838 100644 --- a/lang/cs/settings.php +++ b/lang/cs/settings.php @@ -12,7 +12,7 @@ $lang['userurl'] = 'Relativní URL pro získání uživatelských informací z API (musí vracet JSON data autentizovaného uživatele)'; $lang['authmethod'] = 'Autorizační metoda pro získání uživatelských informací z API'; $lang['scopes'] = 'Požadovaná oprávnění (scopes, oddělená čárkou)'; -$lang['needs-state'] = 'Whether the provider needs and supplies a state parameter in the callback URL.'; +$lang['needs-state'] = 'Poskytovatel potřebuje a poskytuje parametr pro přesměrování na callback URL'; $lang['json-user'] = 'Objektová cesta k uživatelskému jménu (tečková notace)'; $lang['json-name'] = 'Objektová cesta k celému jménu uživatele (tečkovánotace)';