filsh/yii2-oauth2-server

How to use Json Web Token (JWT) in this extension

shallowsmile opened this issue · 3 comments

Hello Sir,I want to get Json Web Token (JWT),and the doc said that "you will need to set 'useJwtToken' => true in module and then define two more configurations: 'public_key' => 'app\storage\PublicKeyStorage' which is the class that implements PublickKeyInterface and 'access_token' => 'app\storage\JwtAccessToken' which implements JwtAccessTokenInterface.php" .But I still didn't know how to do?Could you show me an example of module config about that.Thank you very much!

I had known my problem.I installed this extension is through composer,and this file "Module.php" is different with the one online.That leaded to an error.
The final config I have set:

'modules' => [
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'tokenParamName' => 'accessToken',
'tokenAccessLifetime' => 3600 * 24,
'useJwtToken' => true,
'storageMap' => [
'user_credentials' => 'app\models\User',
'public_key' => 'app\storage\PublicKeyStorage',
'access_token' => 'app\storage\JwtAccessToken'
],
'grantTypes' => [
'client_credentials' => [
'class' => 'OAuth2\GrantType\ClientCredentials',
],
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true
],
],
],
],

Then I could receive a JWT Access Token when I called the Authorization server.
But there was a new problem I couldn't verify access tokens by calling the resource.

The error message:
{"name":"Unauthorized","message":"Your request was made with invalid credentials.","code":0,"status":401,"type":"yii\web\UnauthorizedHttpException"}

Could anyone help me ?
Thank you!

I have solved this problem.

JWT Tokens (2.0.1 branch only)

varp commented

@shallowsmile JWT tokens also in the master branch and in the latest release v2.1.0