对配置变量的更改不会持久化 laravel 5.2

Changes to config variables aren't persisten laravel 5.2

我遇到了一个问题,我需要根据客户端 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 artisan config:clear 重置配置缓存。部署后,您可以 运行 php artisan config:cache 在您的生产服务器上进行性能提升。

问题出在 class 已在登录路径中提供。通过检查 AuthServiceProvider 中 client_idRequest class 并更改那里的配置来修复它。