Skip to content

Commit

Permalink
Merge branch 'release/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshangell committed Jun 22, 2020
2 parents f100f12 + 9604c6c commit 46eebb2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).


## 1.1.3 - 2020-06-22
### Added
- Added the option to check for existing users by setting a custom field and Auth0 metadata key in the config file. Set `uniqueUserFieldHandle` to the field handle and `uniqueUserFieldMetaKey` to the metadata key that will be used to validate the check. This check runs before the email one and will only run if those two values are set in the config file.


## 1.1.2 - 2020-06-05
### Added
- Added a second parmater to the silen login to allow for query params to act as a fallback if the referrer is not present. Use like so: `{% do craft.auth0.silentLogin(['someapp.com','api-someapp.com'], {'ref':'someapp','n':'123'}) %}` or `{% do craft.auth0.silentLogin(['someapp.com','api-someapp.com'], [{'ref':'someapp1','n':'123'},{'ref':'someapp2','n':'456'}]) %}`
Expand Down
4 changes: 3 additions & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
'clientSecret' => null,
'callbackUrl' => null,
'userGroupHandle' => null,
'logoutReturnUrl' => null
'logoutReturnUrl' => null,
'uniqueUserFieldHandle' => null,
'uniqueUserFieldMetaKey' => null
];
10 changes: 10 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ class Settings extends Model
* @var string|null
*/
public $logoutReturnUrl;

/**
* @var string|null
*/
public $uniqueUserFieldHandle;

/**
* @var string|null
*/
public $uniqueUserFieldMetaKey;
}
15 changes: 13 additions & 2 deletions src/services/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function logout()
*/
public function handleCallback()
{
$user = null;
$auth0UserInfo = $this->getUser();

$users = Craft::$app->getUsers();
Expand All @@ -137,10 +138,19 @@ public function handleCallback()
return null;
}

// First try and get Craft user by custom field
if ($this->_settings->uniqueUserFieldHandle && $this->_settings->uniqueUserFieldMetaKey && isset($auth0UserInfo[$this->_settings->uniqueUserFieldMetaKey]) && !empty($auth0UserInfo[$this->_settings->uniqueUserFieldMetaKey])) {
$user = User::findOne([
$this->_settings->uniqueUserFieldHandle => $auth0UserInfo[$this->_settings->uniqueUserFieldMetaKey]
]);
}

// Get the Craft user if we can
$user = $users->getUserByUsernameOrEmail($auth0UserInfo['email']);
if (!$user) {
$user = $users->getUserByUsernameOrEmail($auth0UserInfo['email']);
}

// There isn’t one, so create it first
// There still isn’t one, so create it
if (!$user) {

$user = new User();
Expand Down Expand Up @@ -289,6 +299,7 @@ public function silentLogin($referrerWhitelist = null, $queryParamWhitelist = nu
}
if ($passedParams === count($queryParamSet)) {
$this->_auth0->login();
break;
}
}
}
Expand Down

0 comments on commit 46eebb2

Please sign in to comment.