https://github.com/openid/php-openid
这是我的前同事用来登录Google的图书馆,它将从Google返回open_id id,我的同事只将此ID保存在数据库中供用户授权,谷歌宣布他们将停止支持openid登录,直到2015年/ 04/20,建议用户迁移到openid connect或他们提供的任何方式,并且他们有迁移指令。
https://developers.google.com/identity/protocols/OpenIDConnect
<?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
我成功获得了open_id的id,但它与我通过open-id库登录的id完全不同,我发现如果我更改了客户端ID,open_id的id将会是我也很困惑,如果我不能获得原始的独特open_id id,映射函数的含义是什么,以及如何进行迁移。