Wednesday, March 15, 2017

Changes to config variables aren't persisten laravel 5.2

I'm having a problem where I need to change a config variable used by oauth2 server based on client-id. This is the configuration:

'grant_types' => [
        'password' => [
            'class' => '\League\OAuth2\Server\Grant\PasswordGrant',
            'callback' => '\App\Api\OAuth2\PasswordGrantVerifier@verify',
            'access_token_ttl' => 3600
        ],
]

Then before i issue a token with Authorizer::issueAccessToken(); I set the config variable: config(['oauth2.grant_types.password.access_token_ttl' => 86400]); if I then run dd(config('oauth2')); I get:

'grant_types' => array:1 [
        'password' => array:3 [
            'class' => '\League\OAuth2\Server\Grant\PasswordGrant',
            'callback' => '\App\Api\OAuth2\PasswordGrantVerifier@verify',
            'access_token_ttl' => 86400
        ],
]

But if I let the code run and issue the token the response is still:

{
    "access_token": "HOoODcDzXilakd5TtOv4qqBSBUwEqqWhIL36ALdM",
    "token_type": "Bearer",
    "expires_in": 3600,
    "refresh_token": "6mfyizKlRGC55x6ZY8ROx24UcVeWfljikNZv6ME7",
    "allowed_scopes": [
      "*"
    ],
    "user_is_activated": true
}

If i hardcode the value 'access_token_ttl' => 86400 I get the desired result of:

{
    "access_token": "HOoODcDzXilakd5TtOv4qqBSBUwEqqWhIL36ALdM",
    "token_type": "Bearer",
    "expires_in": 86400,
    "refresh_token": "6mfyizKlRGC55x6ZY8ROx24UcVeWfljikNZv6ME7",
    "allowed_scopes": [
      "*"
    ],
    "user_is_activated": true
}

The problem is that access_token_ttl needs to be dynamic based on the client id. I can't make changes to the vendor library because this would break in future updates. Does someone know of a way to change config variables application wide at runtime that still persists in different methods?



via Sjoerd de Wit

Advertisement