yii2-authclient
yii2-authclient copied to clipboard
Unable to set TokenParamKey in OAuth2 config, gets hard overwritten in OAuth2::createToken().
What steps will reproduce the problem?
I setup an OAuth2 client in my config as following (censored unncessary data):
'clients' => [
'xxx' => [
'name' => 'xxx',
'class' => 'backend\components\myAuth', // Extends OAuth2
'authUrl' => 'xxx',
'tokenUrl' => 'x',
'returnUrl' => 'xxx',
'apiBaseUrl' => 'xxx',
'clientId' => 'xxx',
'clientSecret' => 'xxx',
'stateStorage' => ['class' => 'xxx'],
'scope' => 'xxx',
'accessToken' => ['class' => myOAuthToken::class, 'tokenParamKey' => 'token'],
],
],
Please note the last line of the array: 'accessToken'. I would expect the tokenParamKey of my OAuthToken object to be 'token' after it is created. However, in the OAuth2 class this value seems to get hard overwritten with the value 'access_token', making it impossible to change tokenParamKey in the config. This overwrite seems to be done here: https://github.com/yiisoft/yii2-authclient/blob/c74c89809d5a87358488bd199cdd1ed9af6141b0/src/OAuth2.php#L229
What's expected?
My Token object has the tokenParamKey 'token' that I set in the config.
What do you get instead?
The tokenParamKey of my OAuthToken is 'access_token'.
Additional info
| Q | A |
|---|---|
| Yii version | 2.0.14 |
| Yii Auth Client version | 2.2.9 |
| Yii HTTP Client version | |
| PHP version | 7.4.28 |
| Operating system | Debian 10 in Docker |
Looks like a bug to me. If there's a value, it should not be overwritten. Would you please send a pull request fixing it?
Looks like a bug to me. If there's a value, it should not be overwritten. Would you please send a pull request fixing it?
I'll make a pull request somewhere in the next few days!