api-platform / demo

Demo app for the API Platform framework
https://demo.api-platform.com
MIT License
298 stars 197 forks source link

I'd love to use OIDC configs Discovery, but it is extremely slow, any ideas how to speed it up #413

Closed juslintek closed 3 months ago

juslintek commented 4 months ago

API Platform version(s) affected: 3.3.6

Description
I am facing a problem of this: https://github.com/api-platform/demo/blob/main/api/src/Security/Http/AccessToken/Oidc/OidcDiscoveryTokenHandler.php#L82-L86 being extremely slow that api/vendor/web-token/jwt-library/Core/Util/BigInteger.php:51 $temp = $this->value->toBase(16); is uber slow. Any ideas how to sort this out? It takes almost 2 minutes to populateBigIntegers. Is this the only way to get jws for fetching claims, when using accessToken with keyset from keycloak configs?

How to reproduce
Just use any call on api-platform-demo

Or am I missing something? Running on MacOS ARM v2.

vincentchalamon commented 4 months ago

Hi @juslintek,

Did you install bcmath PHP extension? According to web-token/jwt-library:

GMP or BCMath is highly recommended to improve the library performance

https://github.com/web-token/jwt-library/blob/3.3.x/composer.json#L61

juslintek commented 3 months ago

Thank you! Noticed it is not there, weird that I didn't go while step debugging through some conditions that even check for this extension and based on its existence chooses which handler to use. :-) So installed gmp for best performance and it works great now. From 2mins down to 1.5s :-) Well would be nice if it could be improved even more. :-)