Skip to content
Open
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
36 changes: 36 additions & 0 deletions Auth/GenericOAuth2Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ public function authenticate()

if (! empty($profile)) {
$this->userInfo = new GenericOAuth2UserProvider($this->container, $profile);

$oauth2Username = $this->userInfo->getUsername();

if ($oauth2Username) {
$existingUserId = $this->userModel->getIdByUsername($oauth2Username);

if ($existingUserId) {
$oauth2UserId = $this->userInfo->getExternalId();

if ($oauth2UserId) {
if (DEBUG) {
$this->logger->debug(__METHOD__.': The OAuth2 username is: '.$this->userInfo->getUsername());
$this->logger->debug(__METHOD__.': The Existing User ID is: '.$existingUserId);
$this->logger->debug(__METHOD__.': The OAuth2 User ID is: '.$oauth2UserId);
}

$this->link($existingUserId, $oauth2UserId);
}
}
}

return true;
}

Expand Down Expand Up @@ -134,6 +155,21 @@ public function getProfile()
);
}

/**
* Link user
*
* @access public
* @param integer $userId
* @return bool
*/
public function link($userId, $oauthUserId)
{
return $this->userModel->update(array(
'id' => $userId,
'oauth2_user_id' => $oauthUserId,
));
}

/**
* Unlink user
*
Expand Down