Skip to content

Commit 64905fe

Browse files
committed
update
1 parent 0dff0b9 commit 64905fe

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"ext-mbstring": "*",
2121
"lcobucci/jwt": "4.0.1",
2222
"nette/php-generator": "^3.2",
23-
"topthink/framework": "^6.0"
23+
"topthink/framework": "^6.0",
24+
"xiaodi/think-user": "0.0.1"
2425
},
2526
"require-dev": {
2627
"phpunit/phpunit": "^6.2",

src/Service/Token.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,14 @@ public function automaticRenewalToken(JwtToken $token)
248248

249249
return $token;
250250
}
251+
252+
public function getClaims()
253+
{
254+
return $this->token->claims()->all();
255+
}
256+
257+
public function getClaim($name)
258+
{
259+
return $this->token->claims()->get($name);
260+
}
251261
}

src/Service/User.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use think\App;
88
use xiaodi\JWTAuth\Config\User as Config;
99
use xiaodi\JWTAuth\Exception\JWTException;
10+
use think\User\AuthorizationUserInterface;
1011

1112
class User
1213
{
@@ -74,6 +75,10 @@ public function find()
7475
$uid = $token->claims()->get('jti');
7576

7677
$model = new $class();
77-
return $model->find($uid);
78+
if ($model instanceof AuthorizationUserInterface) {
79+
return $model->getUserById($uid);
80+
} else {
81+
throw new JWTException('implements ' . AuthorizationUserInterface::class);
82+
}
7883
}
7984
}

0 commit comments

Comments
 (0)