doucuo4413 2015-04-17 03:50
浏览 44

OpenId 2.0到OpenId Connect Mapping问题

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本