Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a setting to define the key used to get an user's email #80

Open
wants to merge 4 commits into
base: 4.x-dev
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->{$emailKey});
} else {
// link current user with the remote user
$this->linkAccount($providerUserId);
Expand Down
21 changes: 21 additions & 0 deletions SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -158,6 +164,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();
Expand Down Expand Up @@ -337,6 +344,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.
*
Expand Down
2 changes: 2 additions & 0 deletions lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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, der die E-Mail in den Benutzerinformationen angibt.",
"SettingClientId": "Client ID",
"SettingClientIdHelp": "",
"SettingClientSecret": "Client Secret",
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 that specifies the email in the user information.",
"SettingClientId": "Client ID",
"SettingClientIdHelp": "",
"SettingClientSecret": "Client Secret",
Expand Down
2 changes: 2 additions & 0 deletions lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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é indiquant l'email dans les informations utilisateur.",
"SettingClientId": "Client ID",
"SettingClientIdHelp": "",
"SettingClientSecret": "Client Secret",
Expand Down