Skip to content

Commit

Permalink
Merge pull request #80 from auth0/5.x.x-dev
Browse files Browse the repository at this point in the history
Use  instead of  to identify the Auth0 user
  • Loading branch information
glena authored Aug 30, 2017
2 parents 34ed6a8 + 3515d21 commit 1d83840
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ class MyCustomUserRepository implements Auth0UserRepository {

/* This class is used on api authN to fetch the user based on the jwt.*/
public function getUserByDecodedJWT($jwt) {
/*
* The `sub` claim in the token represents the subject of the token
* and it is always the `user_id`
*/
$jwt->user_id = $jwt->sub;

return $this->upsertUser($jwt);
}

Expand All @@ -68,13 +62,13 @@ class MyCustomUserRepository implements Auth0UserRepository {

protected function upsertUser($profile) {

$user = User::where("auth0id", $profile->user_id)->first();
$user = User::where("auth0id", $profile->sub)->first();

if ($user === null) {
// If not, create one
$user = new User();
$user->email = $profile->email; // you should ask for the email scope
$user->auth0id = $profile->user_id;
$user->auth0id = $profile->sub;
$user->name = $profile->name; // you should ask for the name scope
$user->save();
}
Expand Down
5 changes: 4 additions & 1 deletion src/Auth0/Login/Auth0User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public function __construct($userInfo, $accessToken)
*/
public function getAuthIdentifier()
{
return $this->userInfo['user_id'];
if (isset($this->userInfo['sub'])) {
return $this->userInfo['sub'];
}
return $this->userInfo['user_id'];
}

/**
Expand Down

0 comments on commit 1d83840

Please sign in to comment.