Skip to content

Commit

Permalink
Use instead of to identify the Auth0 user #74
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Aug 30, 2017
1 parent ff199a4 commit 3515d21
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 3515d21

Please sign in to comment.