Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom grant_type requires custom storage_type #101

Open
ebuzzz opened this issue Aug 23, 2016 · 4 comments
Open

Custom grant_type requires custom storage_type #101

ebuzzz opened this issue Aug 23, 2016 · 4 comments

Comments

@ebuzzz
Copy link

ebuzzz commented Aug 23, 2016

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.

@ebuzzz
Copy link
Author

ebuzzz commented Aug 23, 2016

See pull #102 for my fix to this problem.

@yang-he
Copy link

yang-he commented May 6, 2017

@eborned I am having the same issue when trying to implement my own grantTypes. However, your #102 seems not working, it still returns the same "unknown storage key" error.

@ebuzzz
Copy link
Author

ebuzzz commented May 6, 2017 via email

@yang-he
Copy link

yang-he commented May 6, 2017

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,
                ],
            ],
        ],
        ...
        ...
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants