Skip to content

Custom grant_type requires custom storage_type #101

@ebuzzz

Description

@ebuzzz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions