From 51298b298fbac4a06fe6f3b035130f21c919c74a Mon Sep 17 00:00:00 2001
From: Pietro Saccardi <lizardm4@gmail.com>
Date: Tue, 21 Mar 2023 14:09:40 +0100
Subject: [PATCH] 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['tokenurl'] = '';
 $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['tokenurl'] = array('string');
 $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['authurl'] = 'URL pro autentizaci';
 $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['tokenurl'] = 'URL to the token endpoint';
 $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';
-- 
GitLab