-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to parse JSON response #66
Comments
I am also facing the same problem Repro stepsThe example below is of the code I am running and getting error: <?php
declare(strict_types=1);
namespace Application\Controller;
use Exception;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Stevenmaguire\OAuth2\Client\Provider\Keycloak;
class AuthCallbackController
{
/**
* @param Keycloak $provider
*/
public function __construct(private Keycloak $provider)
{
}
/**
* @param Request $request
* @param Response $response
* @return Response
*/
public function __invoke(Request $request, Response $response): Response
{
$params = $request->getQueryParams();
$token = $this->provider->getAccessToken('authorization_code', ['code' => $params['code']]);
$user_data = $this->provider->getResourceOwner($token);
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json');
}
} ScreenshotsEnvironment settings
See the output of the
|
Yeah I'm facing the same issue too. I poked around a little and found that in fact, the 'openid' scope is needed for the userinfo. There is a switch If I add the 'openid' scope in the default scopes above by hand Line 208 of Keycloak.php, everything works fine |
@redor303 i deeply appreciate your feedback, as it helped me solve my problem. According to the official library documentation on Github, the version parameter in the dependency constructor is optional. However, I believe that users who are using versions higher than 20 of Keycloak will need to specify this parameter. Here's my Keycloak constructor looks: new Keycloak([
'authServerUrl' => getenv('AUTH_SERVER_URL'),
'realm' => getenv('REALM'),
'clientId' => getenv('CLIENT_ID'),
'clientSecret' => getenv('CLIENT_SECRET'),
'redirectUri' => getenv('REDIRECT_URI'),
'version' => '21.0.2', # Add this parameter to troubleshoot the issue
]); After configuring the parameter and making a new request, I was able to confirm that everything is working correctly. Now it's possible to retrieve user information without encountering the Screenshot of example: I hadn't noticed the version issue, and only understood the situation better after your explanation. I'm very grateful for your feedback and the clarity of your explanation. |
Upon upgrade of our Keycloak server to 21, login with that library suddenly stopped working. This ought to be more robust; especially with a |
Thank you so much for pointing this out. I was facing the same issue and wasn't able to fix that >] With added scope openid it works |
Next week I will look at and prepare fix |
Thank you so much, i lost hours trying to solve the problem after the system team upgraded their Keycloak version... |
Yes, I managed to make things work using these parameters:
|
@matteo-piazza-exm your solution is working thanks |
Hello.
When executing: $provider->getResourceOwner($token);
I got this error: Failed to parse JSON response: Syntax error /vendor/league/oauth2-client/src/Provider/AbstractProvider.php on line 645
Checked the token on jwt.io - it's ok
How to fix it?
firebase/php-jwt (v6.4.0)
guzzlehttp/guzzle (7.5.0)
guzzlehttp/promises (1.5.2)
guzzlehttp/psr7 (2.4.4)
league/oauth2-client (2.6.1)
paragonie/random_compat (v9.99.100)
psr/http-client (1.0.1)
psr/http-factory (1.0.1)
psr/http-message (1.0.1)
ralouphie/getallheaders (3.0.3)
stevenmaguire/oauth2-keycloak (4.0.0)
symfony/deprecation-contracts (v2.5.2)
The text was updated successfully, but these errors were encountered: