有没有办法通过POST方法使用LightOpenID库进行身份验证?确切地说,在认证之后,Google (例如)返回到指定的URL,但所有数据都是使用GET方法发送给我的,这最终导致了丑陋和长URL。
我的代码是:
define('BASE_URL', 'http://someurl.com');
try {
$openid = new LightOpenID();
if (!isset($_GET['openid_mode'])) {
// no openid mode was set, authenticate user
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->realm = BASE_URL;
$openid->required = array('contact/email');
header('Location: '.$openid->authUrl());
} else if ($_GET['openid_mode'] == 'cancel') {
// user canceled login, redirect them
header('Location: '.BASE_URL);
} else {
// authentication completed, perform license check
if ($openid->validate()) {
$openid->getAttributes();
}
}
} catch (ErrorException $e) {
}因此,在身份验证之后,OP返回到url,如下所示:
http://someurl.com/index.php?openid.ns=http://specs.openid.net/auth/2.0&openid.mode=id_res&openid.op_endpoint=https://www.googl...我想让行动返回到:
http://someurl.com/index.php并使用POST not GET发送所有数据。
发布于 2011-02-16 21:01:51
我也一直在做同样的事情。请参阅下面的代码。我想这应该会有帮助。
<?php
require 'lightopenid/openid.php';
try {
$openid = new LightOpenID;
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://www.google.com/accounts/o8/site-xrds?hd=yourdomain.com';
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last');
header('Location: ' . $openid->authUrl());
}
?>
<form action="?login" method="post">
<button>Login with Google</button>
</form>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication !';
} else {
session_start();
$fname = $openid->ret_fname(); // setting session
$lname = $openid->ret_lname(); // setting session
$email = $openid->ret_email(); // setting session
$_SESSION['admin']['name'] = $fname.' '.$lname; // setting session
$_SESSION['admin']['emailID'] = $email; // setting session
header('Location:approve.php'); // PUT YOUR PAGE/URL HERE.... I THINK THIS SHOULD DO THE TRICK !!!
}
} catch(ErrorException $e) {
echo $e->getMessage();
}发布于 2012-12-03 16:20:02
根据这个问题的最高答案:Response.Redirect with POST instead of Get?,这可能是不可能的
不过,从Google返回给页面处理程序的身份验证响应可能是一个“请求”,而不是“重定向”,所以我仍然不确定。
在收到回复后使用上面的帖子重定向似乎是一个很好的解决办法。
另一种解决方案可能是使用AJAX隐藏整个过程。
https://stackoverflow.com/questions/4946522
复制相似问题