0

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

`

12
  • Check what the response body actually contains. Commented Apr 9 at 8:18
  • logged response and json_decode($response->getBody() as well but it's empty. Commented Apr 9 at 8:24
  • And response status code is? Commented Apr 9 at 8:47
  • I tried to log the whole response like this Log::info('log from getAccessTokenResponse-: ' . json_encode($response)); . response itself is not returning, it is empty. INFO: log from getAccessTokenResponse-: {} Commented Apr 9 at 8:51
  • updated the question: 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 Commented Apr 9 at 8:59

1 Answer 1

0

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.