fetchUserInfoWithToken() return null after successful Google login #25
-
Hi, I have the following error after a successful Google login: Datamweb\ShieldOAuth\Libraries\GoogleOAuth::fetchUserInfoWithToken(): Return value must be of type object, null returned I check the code and I see that it call a Google Api with the token obtained after the login and sent to the call-back ShieldOAuth GET method. Do you have any suggestion in order to understand the issue? Furthermore, one of the request header is 'User-Agent', that has the value 'ShieldOAuth/1.0'. I thought that the issue may be that the application name on Google configuration didn't match this string, but I renamed my app in the OAuth consent screen section and the result was the same. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
Hello, are you using the latest version? composer require datamweb/shield-oauth:dev-develop |
Beta Was this translation helpful? Give feedback.
-
Hi, Following the "Get the keys" guide, I'm in doubt about the needed application scopes in order to perform a successful login. The scopes that I configured are:
At any cases, I tried this scopes and no scopes configured. The result is the same. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have another info for you. I tried the Github login, and, after a successful login, i had the following error: CodeIgniter\Shield\Entities\User::setEmail(): Argument #1 ($email) must be of type string, null given, called in /workspace/vendor/codeigniter4/framework/system/Entity/Entity.php on line 451 It seems that the issue is not only on Google login and maybe the issues are related: both happens after a successful login. Thanks in advice. |
Beta Was this translation helpful? Give feedback.
-
Hi, I analyzed the code of GoogleOAuth. I tried manually (with Postman) the requests performed by the code and they works all fine. The same request with the same parameter (as it seems) generate the error that i wrote in the first post: "Datamweb\ShieldOAuth\Libraries\GoogleOAuth::fetchUserInfoWithToken(): Return value must be of type object, null returned" The real reason of this null is a bad request returned by the server, without a more specific details. Hoping that these details help. Alberto |
Beta Was this translation helpful? Give feedback.
-
Hi, Datamweb\ShieldOAuth\Libraries\GoogleOAuth::fetchUserInfoWithToken(): Return value must be of type object, null returned We resolve this error by changing Curl Request form "GET" to "POST",
protected function fetchUserInfoWithToken(): object
{
// send request to API URL
try {
$response = $this->client->request('**POST**', self::$API_USER_INFO_URL, [
'headers' => [
'Accept' => 'application/json',
'User-Agent' => self::$APPLICATION_NAME . '/1.0',
'Authorization' => 'Bearer ' . $this->getToken(),
],
'http_errors' => false,
]);
} catch (Exception $e) {
exit($e->getMessage());
}
return json_decode($response->getBody());
} |
Beta Was this translation helpful? Give feedback.
-
I tried to apply the fixes suggested by ambikaaSharma on a new branch but I have not the write permissions for a new branch or for push the changes on develop. Then, What's the procedure for ask to appy the bugfixes on the library? The changes needed are:
Thanks in advice |
Beta Was this translation helpful? Give feedback.
Hi,
Datamweb\ShieldOAuth\Libraries\GoogleOAuth::fetchUserInfoWithToken(): Return value must be of type object, null returned
We resolve this error by changing Curl Request form "GET" to "POST",
PROJECT-PATH/vendor/datamweb/shield-oauth/src/Libraries/GoogleOAuth.php