如何验证 google openid 响应

发布于 2024-09-03 16:51:22 字数 259 浏览 2 评论 0原文

我正在尝试向我的用户添加授权抛出 google openid 。我收到 ID (https://www. google.com/accounts/o8/id?id=AIt...Ew-Bo)但我如何检查它是否合法。我的意思是用户可以使用另一个用户的电子邮件创建恶意请求,我如何检查返回的电子邮件和声称的 ID 是否合法?

I'm trying to add authorization throw google openid to my users. I'm receiving id (https://www.google.com/accounts/o8/id?id=AIt...Ew-Bo) but how can i check that it's legit. I mean user can create malicious request with email of another user, how can i check that returning email and claimed id is legit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

原野 2024-09-10 16:51:22

您确实应该使用为此目的创建的众多库之一,而不是尝试自己实现发现和签名验证。以下是各种编程语言的一堆:

http://openid.net/developers/libraries/

Rather than trying to implement discovery and signature verification by yourself, you really ought to use one of the many libraries that have already been created for this purpose. Here are a bunch for various programming languages:

http://openid.net/developers/libraries/

南城追梦 2024-09-10 16:51:22
public function verify_response()
       {$params=$_REQUEST;
        $query=array('openid.signed'=>$params['openid.signed'],
                     'openid.sig'=>$params['openid.sig'],
                     'openid.mode'=>'check_authentication'
                    );
        $keys=explode(',', 'openid.'.strtr($params['openid.signed'], array(','=>',openid.')));
        foreach ($params as $k=>$v)
                {if (in_array($k, $keys))
                    {$query[$k]=$v;
                    }
                }
        $query=http_build_query($query);
        $response=file_get_contents($params['openid.op_endpoint'].'?'.$query);
        return stripos($response, 'is_valid:true')!==false;
       }
public function verify_response()
       {$params=$_REQUEST;
        $query=array('openid.signed'=>$params['openid.signed'],
                     'openid.sig'=>$params['openid.sig'],
                     'openid.mode'=>'check_authentication'
                    );
        $keys=explode(',', 'openid.'.strtr($params['openid.signed'], array(','=>',openid.')));
        foreach ($params as $k=>$v)
                {if (in_array($k, $keys))
                    {$query[$k]=$v;
                    }
                }
        $query=http_build_query($query);
        $response=file_get_contents($params['openid.op_endpoint'].'?'.$query);
        return stripos($response, 'is_valid:true')!==false;
       }
满地尘埃落定 2024-09-10 16:51:22

Google 的 OpenID(Google Apps for Domains OpenID 除外)只是标准 OpenID。您应该采取任何其他 OpenID 所需的所有预防措施,以确保断言合法。你是对的......任何人都可以制作一个 OpenID 肯定断言来欺骗你的 RP,除非你的 RP 验证签名、对标识符执行发现并将该标识符的授权 OP 端点与签署响应的端点相匹配。

至于您是否可以信任该电子邮件地址,那取决于您。您可以选择信任 Google OP 端点,然后您就知道了。

Google's OpenID (Google Apps for Domains OpenID excepted) is just standard OpenID. You should take all the precautions that any other OpenID requires to make sure the assertion is legit. You're right... anyone can craft an OpenID positive assertion to fool your RP unless your RP verifies the signature, performs discovery on the identifier and matches the authorized OP Endpoint for that identifier with the one that signed the response.

As for whether you can trust the email address, that's up to you. You can choose to trust the Google OP endpoint, and then you know.

皓月长歌 2024-09-10 16:51:22
function ValidateWithServer(){
    $params = array(
        'openid.assoc_handle' => urlencode($_REQUEST['openid_assoc_handle']),
        'openid.signed' => urlencode($_REQUEST['openid_signed']),
        'openid.sig' => urlencode($_REQUEST['openid_sig'])
    );
    // Send only required parameters to confirm validity
    $arr_signed = explode(",",str_replace('sreg.','sreg_',$_REQUEST['openid_signed']));
    for ($i=0; $i<count($arr_signed); $i++){
        $s = str_replace('sreg_','sreg.', $arr_signed[$i]);
        $c = $_REQUEST['openid_' . $arr_signed[$i]];
        // if ($c != ""){
            $params['openid.' . $s] = urlencode($c);
        // }
    }
    $params['openid.mode'] = "check_authentication";

    $openid_server = $this->GetOpenIDServer();
    if ($openid_server == false){
        return false;
    }
    $response = $this->CURL_Request($openid_server,'POST',$params);
    $data = $this->splitResponse($response);

    if ($data['is_valid'] == "true") {
        return true;
    }else{
        return false;
    }
}
function ValidateWithServer(){
    $params = array(
        'openid.assoc_handle' => urlencode($_REQUEST['openid_assoc_handle']),
        'openid.signed' => urlencode($_REQUEST['openid_signed']),
        'openid.sig' => urlencode($_REQUEST['openid_sig'])
    );
    // Send only required parameters to confirm validity
    $arr_signed = explode(",",str_replace('sreg.','sreg_',$_REQUEST['openid_signed']));
    for ($i=0; $i<count($arr_signed); $i++){
        $s = str_replace('sreg_','sreg.', $arr_signed[$i]);
        $c = $_REQUEST['openid_' . $arr_signed[$i]];
        // if ($c != ""){
            $params['openid.' . $s] = urlencode($c);
        // }
    }
    $params['openid.mode'] = "check_authentication";

    $openid_server = $this->GetOpenIDServer();
    if ($openid_server == false){
        return false;
    }
    $response = $this->CURL_Request($openid_server,'POST',$params);
    $data = $this->splitResponse($response);

    if ($data['is_valid'] == "true") {
        return true;
    }else{
        return false;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文