lexik / LexikJWTAuthenticationBundle

JWT authentication for your Symfony API
MIT License
2.52k stars 611 forks source link

Generate JWT token using dynamic configuration #1192

Open destructivecreator opened 8 months ago

destructivecreator commented 8 months ago

Here is how I am generating a JWT token in my symfony application: `public function createAccessToken(string $username, array $payload = []): array { $user = JWTUser::createFromPayload($username, $payload);

    $token = $this->jwtManager->createFromPayload($user, $payload);
    $payload = $this->jwtManager->parse($token);

    return [
        'token' => $token,
        'expireAt' => date(DATE_RFC3339_EXTENDED, $payload['exp'])
    ];
}`

I have set the configuration

lexik_jwt_authentication: secret_key: '%kernel.project_dir%/config/jwt/private.pem' public_key: '%kernel.project_dir%/config/jwt/public.pem' pass_phrase: '%env(JWT_PASSPHRASE)%' token_ttl: '%env(JWT_TTL)%'

and it all worked fine, until I have the need to generate a JWT token with dynamic configurations. Is it possible to achieve this somehow, I could not find anything in the documentation. I want to be able to pass the secret_ket and public_key + pass_phase in runtime ?

Ideas and workarounds are welcome :)