【问题标题】:No OpenID Server found at https://www.google.com/accounts/o8/id在 https://www.google.com/accounts/o8/id 上找不到 OpenID 服务器
【发布时间】:2012-11-13 21:07:44
【问题描述】:

有趣的是,我在两个不同的服务器(a.com、b.com)上使用相同的 .php 脚本,结果不同,我猜它们有不同的配置。虽然在 a.com 上我能够很好地完成 SSO 流程,但 b.com 会抛出“在 https://www.google.com/accounts/o8/id 找不到 OpenID 服务器”。

我的 php 脚本如下所示:

$openid = new LightOpenID($_SERVER["HTTP_HOST"]);
$openid->required = array
(
    'contact/email',
    'namePerson/first',
    'namePerson/last'
);
if(!$openid->mode)
{
    $openid->identity = 'https://www.google.com/accounts/o8/id';
    header('Location: ' . $openid->authUrl());
}

在 b.com 中 $openid->authUrl() 行会抛出一个错误: https://www.google.com/accounts/o8/id 找不到 OpenID 服务器

什么服务器配置可能导致这个问题?

【问题讨论】:

  • 如果您在第二台服务器上手动尝试 URL 会发生什么?通过 lynx 或同等渠道?
  • 是的,我认为您为我指明了正确的方向......我已经回答了我的问题。感谢您的反馈

标签: php openid single-sign-on lightopenid


【解决方案1】:

幸运的是,服务器管理员能够快速发现 php 配置中的配置差异 allow_url_fopen = 1 解决了问题

【讨论】:

  • 截至 2015 年 7 月 22 日,他的解决方案不再有效,因为谷歌停止了 OpenID。它已删除所述服务器。
【解决方案2】:

Google 已停止对 OpenID 的支持,并于 2015 年 7 月 22 日删除了此端点。

批准的解决方案/答案已过时。

请迁移到 OAuth。如果使用客户端 (javascript) 登录,this tutorial by google 会附带一个功能齐全的示例。

下面的代码是另一个功能齐全的示例(刚刚测试过),但它更进一步并与服务器端 PHP 脚本集成。请替换您自己的客户 ID(在您的 google developer console 中定义)和 YOURDOMAIN.COM(在 php 中)。

<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <head>
    <meta name="google-signin-scope" content="profile email">
    <meta name="google-signin-client_id" content="1111111111111111111-11111111111111111111111111111111111.apps.googleusercontent.com">
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
    </script>
    <script>
      function signOut() {
        var auth2 = gapi.auth2.getAuthInstance();
        auth2.signOut().then(function () {
            console.log('User signed out.');
            userDataClear();
        });
      }
      function disassociate() {
        var auth2 = gapi.auth2.getAuthInstance();
        auth2.disconnect().then(function () {
            console.log('User disconnected from association with app.');
            userDataClear();
        });
      }
      function onSignIn(googleUser) {
            // Useful data for your client-side scripts:
            var profile = googleUser.getBasicProfile();
            console.log("ID: " + profile.getId()); // Don't send this directly to your server!
            // The ID token you need to pass to your backend:
            var id_token = googleUser.getAuthResponse().id_token;
            var xhr = new XMLHttpRequest();
            xhr.open('POST', 'http://YOURDOMAIN.COM/twoStep02.php');
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.onload = function() {
                console.log('NEW Signed in Google Client ID: ' + xhr.responseText);
            };
        xhr.send('idtoken=' + id_token);
            console.log("ID Token: " + id_token);
            userDataDisplay(profile);
      }
      function userDataDisplay(profile) {
        document.getElementById("foto").innerHTML = '<img src="' + profile.getImageUrl() + '"></img>';
        document.getElementById("email").innerHTML = profile.getEmail();
        document.getElementById("nome").innerHTML = profile.getName();
      }
      function userDataClear() {
        document.getElementById("foto").innerHTML = ' ';
        document.getElementById("email").innerHTML = ' ';
        document.getElementById("nome").innerHTML = ' ';
      }
   </script>
  </head>
  <body>
    <div id="login-button" class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
    <div><a href="/#" onclick="signOut();">Sign out</a></div>
    <div><a href="/#" onclick="disassociate();">Disassociate App and Site (easily undone)</a></div>
    <div id="foto"></div>
    <div id="nome"></div>
    <div id="email"></div>
  </body>
</html>

这是 jquery/ajax 调用的 php 端 (twoStep.php)

<?php

    $idToken = $_POST["idtoken"];
    $url = 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token='.$idToken;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $json = json_decode($response, true);
    curl_close($ch);

    $userEmail = $json["email"];
    $clientId = $json["azp"];
    print_r($json); // returns array console readable

?> 

提示 4 个新手:通过右键单击页面的任何元素并选择“检查元素”来读取控制台输出,然后切换到 CONSOLE 选项卡。

【讨论】:

  • 澄清一下,Google 建议专门迁移到 OpenID Connect 而不是直接迁移到 OAuth/OAuth2。
  • 请发链接。
  • 抱歉,现在找不到我在哪里看到的了。 This 解决了这个问题,尽管它不是来自 Google。
  • 会给它 peekasap。 tks.
猜你喜欢
  • 2016-12-11
  • 1970-01-01
  • 2018-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多