From fa30ccba070dffab5d5a48226db56ef412283196 Mon Sep 17 00:00:00 2001 From: Maxime Morille Date: Tue, 22 Nov 2022 17:13:33 +0100 Subject: [PATCH 1/4] Adds a setting to define the key used to get an user's email --- Controller.php | 3 ++- SystemSettings.php | 15 +++++++++++++++ lang/de.json | 2 ++ lang/en.json | 2 ++ lang/fr.json | 2 ++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Controller.php b/Controller.php index 8565c11..c90912d 100644 --- a/Controller.php +++ b/Controller.php @@ -275,7 +275,8 @@ public function callback() if (empty($user)) { if (Piwik::isUserIsAnonymous()) { // user with the remote id is currently not in our database - $this->signupUser($settings, $providerUserId, $result->email); + $emailKey = $settings->emailKey->getValue(); + $this->signupUser($settings, $providerUserId, $result->{$email}); } else { // link current user with the remote user $this->linkAccount($providerUserId); diff --git a/SystemSettings.php b/SystemSettings.php index 08f2d2e..d4a7a79 100644 --- a/SystemSettings.php +++ b/SystemSettings.php @@ -158,6 +158,7 @@ protected function init() $this->userinfoUrl = $this->createUserinfoUrlSetting(); $this->endSessionUrl = $this->createEndSessionUrlSetting(); $this->userinfoId = $this->createUserinfoIdSetting(); + $this->emailKey = $this->createEmailKeySetting(); $this->clientId = $this->createClientIdSetting(); $this->clientSecret = $this->createClientSecretSetting(); $this->scope = $this->createScopeSetting(); @@ -337,6 +338,20 @@ private function createUserinfoIdSetting() : SystemSetting }); } + /** + * Add email key setting. + * + * @return SystemSetting + */ + private function createEmailKeySetting() : SystemSetting + { + return $this->makeSetting("emailKey", $default = "email", FieldConfig::TYPE_STRING, function(FieldConfig $field) { + $field->title = Piwik::translate("LoginOIDC_SettingEmailKey"); + $field->description = Piwik::translate("LoginOIDC_SettingEmailKeyHelp"); + $field->uiControl = FieldConfig::UI_CONTROL_TEXT; + }); + } + /** * Add client id setting. * diff --git a/lang/de.json b/lang/de.json index 3d1d44c..892ba37 100644 --- a/lang/de.json +++ b/lang/de.json @@ -20,6 +20,8 @@ "SettingEndSessionUrlHelp": "Nach dem Logout wird der Benutzer zu dieser URL weitergeleitet, damit die Session beim Provider beendet wird. Bei Unklarheit sollte dieses Feld freigelassen werden.", "SettingUserinfoId": "Userinfo ID", "SettingUserinfoIdHelp": "Name des Feldes, in dem die Benutzer-ID enthalten ist. Normalerweise, für OpenID Connect Dienste wie Auth0, ist das 'sub'. Github gibt die eindeutige Benutzer-ID in dem Feld 'id' an.", + "SettingEmailKey": "Email key", + "SettingEmailKeyHelp": "Schlüssel des Objekts User info, das die E-Mail des Benutzers enthält.", "SettingClientId": "Client ID", "SettingClientIdHelp": "", "SettingClientSecret": "Client Secret", diff --git a/lang/en.json b/lang/en.json index 411697c..64d28ea 100644 --- a/lang/en.json +++ b/lang/en.json @@ -22,6 +22,8 @@ "SettingEndSessionUrlHelp": "After logging out, the user is redirected to this URL to end the session at the provider. If you are unsure, just leave this field empty.", "SettingUserinfoId": "Userinfo ID", "SettingUserinfoIdHelp": "Name of the unique user id field in the userinfo response. Usually for OpenID Connect services like Auth0 this is 'sub'. Github provides the user id in 'id'.", + "SettingEmailKey": "Email key", + "SettingEmailKeyHelp": "Key of the User info object containing the user's email.", "SettingClientId": "Client ID", "SettingClientIdHelp": "", "SettingClientSecret": "Client Secret", diff --git a/lang/fr.json b/lang/fr.json index 7820f3b..c1d46af 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -20,6 +20,8 @@ "SettingEndSessionUrlHelp": "", "SettingUserinfoId": "ID Userinfo", "SettingUserinfoIdHelp": "Nom du champ de l'identifiant unique utilisateur dans la réponse 'userinfo'. Habituellement, pour les services de connexion OpenID Connect comme Auth0, il s'agit de 'sub'. Github fourni l'identifiant utilisateur avec 'id'.", + "SettingEmailKey": "Clé de l'email", + "SettingEmailKeyHelp": "Clé de l'objet utilisateur indiquant l'email.", "SettingClientId": "Client ID", "SettingClientIdHelp": "", "SettingClientSecret": "Client Secret", From 171a179c3d58312d70c3daa3739178770a2a96f7 Mon Sep 17 00:00:00 2001 From: Maxime Morille Date: Thu, 24 Nov 2022 15:29:34 +0100 Subject: [PATCH 2/4] Use correct variable name --- Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller.php b/Controller.php index c90912d..46f104b 100644 --- a/Controller.php +++ b/Controller.php @@ -276,7 +276,7 @@ public function callback() if (Piwik::isUserIsAnonymous()) { // user with the remote id is currently not in our database $emailKey = $settings->emailKey->getValue(); - $this->signupUser($settings, $providerUserId, $result->{$email}); + $this->signupUser($settings, $providerUserId, $result->{$emailKey}); } else { // link current user with the remote user $this->linkAccount($providerUserId); From 5d7c1ce567d8fea2ba1e4c98cedbaf49e4709751 Mon Sep 17 00:00:00 2001 From: Maxime Morille Date: Thu, 24 Nov 2022 17:05:23 +0100 Subject: [PATCH 3/4] Improve translations --- lang/de.json | 2 +- lang/en.json | 2 +- lang/fr.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lang/de.json b/lang/de.json index 892ba37..65f9b18 100644 --- a/lang/de.json +++ b/lang/de.json @@ -21,7 +21,7 @@ "SettingUserinfoId": "Userinfo ID", "SettingUserinfoIdHelp": "Name des Feldes, in dem die Benutzer-ID enthalten ist. Normalerweise, für OpenID Connect Dienste wie Auth0, ist das 'sub'. Github gibt die eindeutige Benutzer-ID in dem Feld 'id' an.", "SettingEmailKey": "Email key", - "SettingEmailKeyHelp": "Schlüssel des Objekts User info, das die E-Mail des Benutzers enthält.", + "SettingEmailKeyHelp": "Schlüssel, der die E-Mail in den Benutzerinformationen angibt.", "SettingClientId": "Client ID", "SettingClientIdHelp": "", "SettingClientSecret": "Client Secret", diff --git a/lang/en.json b/lang/en.json index 64d28ea..0f0ebfe 100644 --- a/lang/en.json +++ b/lang/en.json @@ -23,7 +23,7 @@ "SettingUserinfoId": "Userinfo ID", "SettingUserinfoIdHelp": "Name of the unique user id field in the userinfo response. Usually for OpenID Connect services like Auth0 this is 'sub'. Github provides the user id in 'id'.", "SettingEmailKey": "Email key", - "SettingEmailKeyHelp": "Key of the User info object containing the user's email.", + "SettingEmailKeyHelp": "Key that specifies the email in the user information.", "SettingClientId": "Client ID", "SettingClientIdHelp": "", "SettingClientSecret": "Client Secret", diff --git a/lang/fr.json b/lang/fr.json index c1d46af..0c08b22 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -21,7 +21,7 @@ "SettingUserinfoId": "ID Userinfo", "SettingUserinfoIdHelp": "Nom du champ de l'identifiant unique utilisateur dans la réponse 'userinfo'. Habituellement, pour les services de connexion OpenID Connect comme Auth0, il s'agit de 'sub'. Github fourni l'identifiant utilisateur avec 'id'.", "SettingEmailKey": "Clé de l'email", - "SettingEmailKeyHelp": "Clé de l'objet utilisateur indiquant l'email.", + "SettingEmailKeyHelp": "Clé indiquant l'email dans les informations utilisateur.", "SettingClientId": "Client ID", "SettingClientIdHelp": "", "SettingClientSecret": "Client Secret", From 0ac7b13ec011482cf73fd7cadef740fd5c3b0737 Mon Sep 17 00:00:00 2001 From: Maxime Morille Date: Mon, 18 Dec 2023 17:38:59 +0100 Subject: [PATCH 4/4] Adds missing field declaration --- SystemSettings.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SystemSettings.php b/SystemSettings.php index d4a7a79..213e16a 100644 --- a/SystemSettings.php +++ b/SystemSettings.php @@ -104,6 +104,12 @@ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings */ public $userinfoId; + /** + * The name of the field used to retrieve the user's email + * + * @var string + */ + public $emailKey; /** * The client id given by the provider. *