Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
edenleung committed Apr 21, 2021
1 parent 0dff0b9 commit 64905fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"ext-mbstring": "*",
"lcobucci/jwt": "4.0.1",
"nette/php-generator": "^3.2",
"topthink/framework": "^6.0"
"topthink/framework": "^6.0",
"xiaodi/think-user": "0.0.1"
},
"require-dev": {
"phpunit/phpunit": "^6.2",
Expand Down
10 changes: 10 additions & 0 deletions src/Service/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,14 @@ public function automaticRenewalToken(JwtToken $token)

return $token;
}

public function getClaims()
{
return $this->token->claims()->all();
}

public function getClaim($name)
{
return $this->token->claims()->get($name);
}
}
7 changes: 6 additions & 1 deletion src/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use think\App;
use xiaodi\JWTAuth\Config\User as Config;
use xiaodi\JWTAuth\Exception\JWTException;
use think\User\AuthorizationUserInterface;

class User
{
Expand Down Expand Up @@ -74,6 +75,10 @@ public function find()
$uid = $token->claims()->get('jti');

$model = new $class();
return $model->find($uid);
if ($model instanceof AuthorizationUserInterface) {
return $model->getUserById($uid);
} else {
throw new JWTException('implements ' . AuthorizationUserInterface::class);
}
}
}

0 comments on commit 64905fe

Please sign in to comment.