2017-03-15 33 views
0

我遇到了一個問題,我需要根據客戶端ID更改由oauth2服務器使用的配置變量。這是配置:配置變量的變化不是持久化5.2

'grant_types' => [ 
     'password' => [ 
      'class' => '\League\OAuth2\Server\Grant\PasswordGrant', 
      'callback' => '\App\Api\OAuth2\[email protected]', 
      '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\[email protected]', 
      '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動態。我無法更改供應商庫,因爲這會在未來的更新中破壞。有人知道在運行時在應用程序範圍內更改配置變量的方法,該方法仍然存在於不同的方法中嗎?

回答

0

問題在於在登錄路線中已經提供了班級。通過在AuthServiceProvider中檢查Request類中的client_id並更改其中的配置來修復它。

0

檢查您是否沒有緩存您的配置,請運行php artisan config:clear來重置配置緩存。在部署完成後,您可以在生產服務器上運行php artisan config:cache以提高性能。

+0

如果這是問題,我會注意到它,因爲那樣當硬編碼access_token_ttl的缺省值時它不會改變響應的值,但它確實不是緩存問題。 –