Skip to content

Commit

Permalink
Merge pull request #17 from openeuropa/OPENEUROPA-164
Browse files Browse the repository at this point in the history
OPENEUROPA-164: Authentication: fix login error on ECAS redirect
  • Loading branch information
ademarco authored Aug 23, 2018
2 parents 28574b0 + 09dba4f commit 1c16330
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ protected function attachRoles(UserInterface $account, PCasUserInterface $pCasUs
* @throws \Exception
*/
protected function doLoadAccount(PCasUserInterface $pCasUser) {
$mail = $pCasUser->get('cas:email');
if (empty($mail)) {
throw new \Exception('Email address not provided by OE Authentication.');
$username = $pCasUser->get('cas:user');
if ($username === NULL) {
throw new \Exception('No username found on the PCas user.');
}
$accounts = $this->userStorage->loadByProperties(['mail' => $mail]);

$accounts = $this->userStorage->loadByProperties(['name' => $username]);
if (empty($accounts)) {
// Account does not exist, creation of new accounts is handled in.
// @see \Drupal\oe_authentication\Controller\OeAuthenticationController::login.
Expand All @@ -107,6 +108,7 @@ protected function doLoadAccount(PCasUserInterface $pCasUser) {
*/
protected function createAccount(PCasUserInterface $pCasUser) {
$name = $this->uniqueUsername($pCasUser->getUsername());
// @todo Fix the retrieval of the email as not all CAS replies have "cas:email".
$mail = $pCasUser->get('cas:email');

/** @var \Drupal\user\Entity\User $account */
Expand Down

0 comments on commit 1c16330

Please sign in to comment.