Php 使用POST方法进行LightOpenID身份验证

Php 使用POST方法进行LightOpenID身份验证,php,post,openid,lightopenid,Php,Post,Openid,Lightopenid,是否有一种使用POST方法使用LightOpenID库进行身份验证的方法?确切地说,在验证之后,Google(例如)返回到指定的URL,但所有数据都使用GET方法发送给我,结果变成丑陋的长URL 我的代码是: define('BASE_URL', 'http://someurl.com'); try { $openid = new LightOpenID(); if (!isset($_GET['openid_mode'])) { // no openid m

是否有一种使用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...
我想让OP回到:

http://someurl.com/index.php

并使用POST not GET发送所有数据。

我一直在做同样的工作。请参阅下面的代码。我想这应该会有帮助。

<?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();
}

使用谷歌登录

根据对这个问题的最高回答,这可能是不可能的:

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

在回复后使用上述帖子重定向自己似乎是一个很好的解决方法


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

如果您主要关心的是URL是否好看,那么在获取所有数据后,让您的端点重定向到正常的位置即可。虽然LOID支持POST,但我怀疑每一个OID提供商都是如此灵活。我认为谷歌应该是支持它的首选。如何在LOID中指定使用POST?那么,一旦用户登录,是否使用POST方法而不是GET返回所有数据?
fname=$openid->ret_fname()$lname=$openid->ret_lname()$email=$openid->ret_email()
您将在这些php变量中获得fname、lname和email的所有值。现在你可以随心所欲地使用它们了。我更喜欢在您的会话中设置它们。