3

有没有办法使用 POST 方法使用 LightOpenID 库进行身份验证?确切地说,在通过身份验证后,谷歌(例如)返回到指定的 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...

我希望 OP 回到:

http://someurl.com/index.php

并使用 POST 而不是 GET 发送所有数据。

4

2 回答 2

1

我一直在做同样的事情。请参阅下面的代码。我认为这应该有所帮助。

<?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();
}
于 2011-02-16T13:01:50.763 回答
0

根据这个问题的最佳答案,这可能是不可能的:Response.Redirect with POST instead of Get?

从 Google 返回到您的页面处理程序的身份验证响应可能是“请求”而不是“重定向”,所以我仍然不确定。

在使用上述 POST 响应后重定向自己似乎是一个很好的解决方法。

另一种解决方案可能是使用 AJAX 隐藏整个过程。

于 2012-12-03T08:20:01.727 回答