Skip to content

Instantly share code, notes, and snippets.

@TheBojda
Created April 1, 2020 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBojda/8fec388254ecc89d78ff9d54002fb81e to your computer and use it in GitHub Desktop.
Save TheBojda/8fec388254ecc89d78ff9d54002fb81e to your computer and use it in GitHub Desktop.
Firebase Auth - Verify ID token, and get user info in PHP with CURL
function getUserByToken($token)
{
$data = array("idToken" => $token);
$data_string = json_encode($data);
$ch = curl_init('https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=' . API_KEY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
)
);
$response = json_decode(curl_exec($ch));
return $response->users[0];
}
@chalchis
Copy link

hello sorry I'm new to firebase is this code currently functional in firebase?

@TheBojda
Copy link
Author

hello sorry I'm new to firebase is this code currently functional in firebase?

As I see, it is not functioning from June 30, 2020. :(
(https://developers.google.com/identity/toolkit/migrate-identityplatform)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment