yii2-oauth2-server
yii2-oauth2-server copied to clipboard
Custom grant_type requires custom storage_type
I've been working on a custom grant_type to incorporate OTP in the normal user_credentials grant_type. This requires a storageMap property with the same name. The main problem is that the base library (bshaffes/oauth2) only accepts a few fixed values as keys for the storage map:
So this won't work:
'storageMap' => [
'user_credentials' => 'common\models\User',
'user_credentials_otp' => 'common\models\User',
],
'grantTypes' => [
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'user_credentials_otp' => [
'class' => 'common\components\GrantType\UserCredentialsOtp',
],
]
It returns the error:
"unknown storage key "user_credentials_otp", must be one of [access_token, authorization_code, client_credentials, client, refresh_token, user_credentials, user_claims, public_key, jwt_bearer, scope]"
I've forked the library and added a custom storageName property to the grantType configuration. This will allow me to override the storageMap key for a specific grantType.
'storageMap' => [
'user_credentials' => 'common\models\User',
'user_credentials_otp' => 'common\models\User',
],
'grantTypes' => [
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'user_credentials_otp' => [
'class' => 'common\components\GrantType\UserCredentialsOtp',
'storageName' => 'user_credentials'
],
]
Am I the only one having this problem? And would this be something we can add to the library? It's backwards compatible and I think the only way to support this right now.
See pull #102 for my fix to this problem.
@eborned I am having the same issue when trying to implement my own grantTypes. However, your https://github.com/Filsh/yii2-oauth2-server/pull/102 seems not working, it still returns the same "unknown storage key" error.
Can you show your config?
On May 6, 2017 13:07, "Yang He" [email protected] wrote:
@eborned https://github.com/eborned I am having the same issue when trying to implement my own grantTypes. However, your #102 https://github.com/Filsh/yii2-oauth2-server/pull/102 seems not working, it still returns the same "unknown storage key" error.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Filsh/yii2-oauth2-server/issues/101#issuecomment-299632497, or mute the thread https://github.com/notifications/unsubscribe-auth/AD4OYpzz3Au30mdnc7lD6TgWmfomUuD3ks5r3FRigaJpZM4Jqq13 .
Hi @eborned, please see my config in below, it is actually same as you demonstrated above.
'modules' => [
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'tokenParamName' => 'access_token',
'tokenAccessLifetime' => 3600*24,
'storageMap' => [
'user_credentials' => 'api\common\models\User',
'user_credentials_custom' => 'api\common\models\User',
],
'grantTypes' => [
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'user_credentials_custom' => [
'class' => 'api\components\OAuth2\GrantType\WechatAppCode',
'storageName' => 'user_credentials_custom',
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true,
],
],
],
...
...
],