We are using socialiteproviders/laravelpassport for OAUTH2.0 integration and try to authenticate users. The first call return expected code and state values Socialite::driver('laravelpassport')->scopes(['offline_access'])->redirect()->getTargetUrl()
Now using code and state we are triggering another call Socialite::driver('laravelpassport')->stateless()->setHttpClient(new \GuzzleHttp\Client(['verify' => false]))->user()
, which is not returning the users details. On further investigation we found out that the function getAccessTokenResponse($code)
is not returning the accessToken as response. below is the function which is returning empty response {}.
public function getAccessTokenResponse($code)
{
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
RequestOptions::HEADERS => $this->getTokenHeaders($code),
RequestOptions::FORM_PARAMS => $this->getTokenFields($code),
]);
return json_decode($response->getBody(), true);
}
getTokenHeaders returns : return ['Accept' => 'application/json'];
getToeknFields return:
grant_type' => 'authorization_code',
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'code' => $code,
'redirect_uri' => $this->redirectUrl,
not sure where are we missing something, as the accesstoken is not coming in response we are unable to fetch the users details. Any help us much appreciated. thank you. Note: We are authenticating users using CAS, and on CAS server we can see that the user Access Token got generated but in response of above function we are getting empty. response on CAS server
Created access token TST-accesstokengenerated, now encoding it as base64
2025-04-09 INFO OAuth access token response: access_token=encodedTST-accesstokengenerated&expires_in=6199
`
The default provider functions using below code to return the response which in my case was returning null as response
return json_decode((string) $response->getBody(), true);
But I override it with the the return statement as below, which returned me the the response form IDAM CAS correctly.
return $response->body();