如何实现google、yahoo等的openid
我正在尝试实现 OpenID,为此我下载 http://www.openidenabled.com/php-openid< /a> 并从中选择 Auth 文件夹,将任何内容更改为 localhost 目录并创建一个 index.php 文件,其代码如下:
<?php
if (!isset($_POST['submit'])) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>OPENID TESTING</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Sign in with your OpenID: <br/>
<input type="text" name="id" size="30" />
<br />
<input type="submit" name="submit" value="Log In" />
</form>
</body>
</html>
<?php
} else {
// check for form input
if (trim($_POST['id'] == '')) {
die("ERROR: Please enter a valid OpenID.");
}
// include files
require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/FileStore.php";
// start session (needed for YADIS)
session_start();
// create file storage area for OpenID data
$store = new Auth_OpenID_FileStore('./oid_store');
// create OpenID consumer
$consumer = new Auth_OpenID_Consumer($store);
// begin sign-in process
// create an authentication request to the OpenID provider
$auth = $consumer->begin($_POST['id']);
if (!$auth) {
die("ERROR: Please enter a valid OpenID.");
}
// redirect to OpenID provider for authentication
$url = $auth->redirectURL('http://localhost/', 'http://localhost/oid_return.php');
header('Location: ' . $url);
}
?>
现在,当我尝试从 worldpress 或 myopenid.com 填写 id 时,它会被识别并转移给我到提供商页面进行身份验证,但这没有发生与谷歌、雅虎或其他服务提供商的情况。我必须为 Google 或 Yahoo 实施什么
I am trying to implement OpenID and for that I download http://www.openidenabled.com/php-openid and from that I picked up Auth folder with changing any thing to localhost directory and created a index.php file and whose code is as below:
<?php
if (!isset($_POST['submit'])) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>OPENID TESTING</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Sign in with your OpenID: <br/>
<input type="text" name="id" size="30" />
<br />
<input type="submit" name="submit" value="Log In" />
</form>
</body>
</html>
<?php
} else {
// check for form input
if (trim($_POST['id'] == '')) {
die("ERROR: Please enter a valid OpenID.");
}
// include files
require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/FileStore.php";
// start session (needed for YADIS)
session_start();
// create file storage area for OpenID data
$store = new Auth_OpenID_FileStore('./oid_store');
// create OpenID consumer
$consumer = new Auth_OpenID_Consumer($store);
// begin sign-in process
// create an authentication request to the OpenID provider
$auth = $consumer->begin($_POST['id']);
if (!$auth) {
die("ERROR: Please enter a valid OpenID.");
}
// redirect to OpenID provider for authentication
$url = $auth->redirectURL('http://localhost/', 'http://localhost/oid_return.php');
header('Location: ' . $url);
}
?>
Now when I try to fill id from worldpress or myopenid.com is recognised and transfer me to the provider page for authentication but this is not happening with Google, yahoo or others service providers case. What I have to implement for Google or Yahoo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用 PHP LightOpenID 库(参见 gitorious)来使用户能够登录我的网站和他们的 Google 帐户。对于其他 OpenID 提供商,您只需更改
$openid->identity
字段。它为我们处理所有身份验证流程。您无需担心令牌之类的事情。这里是我显示“使用 Google 登录”链接的页面:
当点击该链接时,会出现一个 Google 页面,要求他进行身份验证和/或授权您检索他的电子邮件。
然后他将被重定向到登陆页面
$openid->returnUrl
。该页面的代码应该是:如果您想从用户那里检索更多信息,您必须将它们添加到第一页的
$openid->required
中。例如:如果用户接受,您将可以在第二页中获取他的名字和姓氏:
希望有帮助!
I am using the PHP LightOpenID library (see on gitorious) to make users able to log into my website with their Google account. For other OpenID provider, you just have to change the
$openid->identity
field. It handles all the authentication flow for us. You don't need to bother about token and stuff.Here the page where I display the "Login with Google" link :
When the click on the link, a Google page will appear ask him to authenticate and/or authorize you to retrieve his email.
Then he will be redirect to the landing page
$openid->returnUrl
. The code for that page should be :If you want to retrieve more info from the user, you have to add them to
$openid->required
in the first page. For instance :will let you, if the user accepts it, to get his first and last names as well in the second page :
Hope that helps !