【发布时间】:2017-03-15 11:56:52
【问题描述】:
我遇到了一个问题,我需要根据客户端 ID 更改 oauth2 服务器使用的配置变量。这是配置:
'grant_types' => [
'password' => [
'class' => '\League\OAuth2\Server\Grant\PasswordGrant',
'callback' => '\App\Api\OAuth2\PasswordGrantVerifier@verify',
'access_token_ttl' => 3600
],
]
然后在我使用Authorizer::issueAccessToken(); 发出令牌之前,我设置了配置变量:config(['oauth2.grant_types.password.access_token_ttl' => 86400]);,如果我随后运行dd(config('oauth2'));,我得到:
'grant_types' => array:1 [
'password' => array:3 [
'class' => '\League\OAuth2\Server\Grant\PasswordGrant',
'callback' => '\App\Api\OAuth2\PasswordGrantVerifier@verify',
'access_token_ttl' => 86400
],
]
但如果我让代码运行并发出令牌,响应仍然是:
{
"access_token": "HOoODcDzXilakd5TtOv4qqBSBUwEqqWhIL36ALdM",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "6mfyizKlRGC55x6ZY8ROx24UcVeWfljikNZv6ME7",
"allowed_scopes": [
"*"
],
"user_is_activated": true
}
如果我对值 'access_token_ttl' => 86400 进行硬编码,我会得到所需的结果:
{
"access_token": "HOoODcDzXilakd5TtOv4qqBSBUwEqqWhIL36ALdM",
"token_type": "Bearer",
"expires_in": 86400,
"refresh_token": "6mfyizKlRGC55x6ZY8ROx24UcVeWfljikNZv6ME7",
"allowed_scopes": [
"*"
],
"user_is_activated": true
}
问题是access_token_ttl 需要根据客户端 ID 进行动态处理。我无法更改供应商库,因为这会在未来的更新中中断。有人知道在运行时更改应用程序范围内的配置变量的方法仍然存在于不同的方法中吗?
【问题讨论】:
标签: php laravel oauth-2.0 laravel-5.2 config