https://github.com/openid/php-openid
This is the library which my ex-co-workers use to login Google, it will return open_id id from Google, my colleague only save this id in database for user authorization, Google announce they will stop support openid login until 2015/04/20, suggest user migrate to openid connect or any way they offer, and they have a migration instruction.
https://developers.google.com/identity/protocols/OpenIDConnect
Code Part
<?php
$id = '';
$secret = '';
$url = '';
$state = md5(rand());
if (isset($_GET['code']) === true) {
$authUrl = 'https://www.googleapis.com/oauth2/v3/token';
$fields = array(
'code' => $_GET['code'],
'client_id' => $id,
'client_secret' => $secret,
'redirect_uri' => $url,
'grant_type' => 'authorization_code',
);
$result = json_decode(Api::curl($authUrl, 'POST', $fields));
$accessToken = $result->access_token;
$idToken = $result->id_token;
$encodes = explode('.', $idToken);
$json = json_decode(base64_decode($encodes[1]));
foreach ($json as $key => $value) {
echo '<pre>'; var_dump($key . ': ' . $value); echo '</pre>';
}
} else {
$authUrl = "https://accounts.google.com/o/oauth2/auth?client_id={$id}&response_type=code&scope=openid%20email&redirect_uri={$url}&state={$state}&openid.realm={$url}";
Api::redirect($authUrl);
}
openid_id: https://www.google.com/accounts/o8/id?id=AItOawnryGxnJ0nA4Rq62G9nKCcQt_YsmXlqjxw
I successful got open_id's id, but it's totally different from the id I login by open-id library, and I found that if I change client id, open_id's id will be different as well, I was confused, if I can't get original unique open_id's id, what is the meaning of mapping function, and how to do the migration.