【问题标题】:Codeigniter OpenID AuthenticationCodeigniter OpenID 身份验证
【发布时间】:2011-12-10 03:28:04
【问题描述】:

我是 OpenID 概念的新手,最近尝试使用 JanRain PHP 5 系统为 CodeIgniter 实现 OpenID Library。但是在从 Google 和 Yahoo 等网站检索简单数据时遇到了一些问题...

我的 OpenID 库配置文件如下所示:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    $config['openid_storepath'] = 'tmp';
    $config['openid_policy'] = 'test/policy';
    $config['openid_required'] = array('email');
    $config['openid_optional'] = array('fullname');
    $config['openid_request_to'] = 'test/check';
?>

但是,我无法获取“电子邮件”或“全名”值。我尝试填写其他字段(如“昵称”),但这也没有产生结果。此外,JanRain docs 中指定的许多其他选项(例如 'verifiedEmail' 和 'preferredUsername')仅导致 SREG 错误。

身份验证成功,因为它们返回一条成功消息,但我如何才能访问我请求的信息?

编辑:这是返回 URL:

http://www.{Site}.net/v2/test/check?janrain_nonce=2011-12-10T05:53:01ZFXVT02&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=id_res&openid.return_to=http%3A%2F%2Fwww.{Site}.net%2Fv2%2Ftest%2Fcheck%3Fjanrain_nonce%3D2011-12-10T05%3A53%3A01ZFXVT02&openid.claimed_id=https%3A%2F%2Fme.yahoo.com%2Fa%2F{Token}%23df6f7&openid.identity=https%3A%2F%2Fme.yahoo.com%2Fa%2F{Token}&openid.assoc_handle={Handle}&openid.realm=http%3A%2F%2Fwww.{Site}.net%2Fv2%2F&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.response_nonce=2011-12-10T05%3A53%3{Nonce Token}&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Csigned%2Cpape.auth_level.nist&openid.op_endpoint=https%3A%2F%2Fopen.login.yahooapis.com%2Fopenid%2Fop%2Fauth&openid.pape.auth_level.nist=0&openid.sig=CUa39ZjhGE8nWc7TMvbS8UFlwjQ%3D

谢谢!

【问题讨论】:

  • @RohanPatil 我一直在关注该指南并阅读了一些 cmets,但尚未找到解决方案...
  • @DFranks 我假设您已将用户重定向到 yahoo/google 并且他们已经登录并被重定向回您的应用程序。如果是这种情况,您可以显示 URL 及其参数吗?
  • @umeshawasthi 我在上面的返回网址中进行了编辑。
  • @DFranks 你为什么不在雅虎中使用属性交换它支持这个东西,它会给你带来你对它的期望。

标签: php codeigniter openid attribute-exchange


【解决方案1】:

我无法在 PHP 中为您提供帮助,但可以向您展示我在 java 中开发的适用于 yahoo 的代码

当我为雅虎创建 AuthenticationUrl() 时,这就是我正在做的事情

 StringBuilder sb = new StringBuilder(1024);
        sb.append(endpoint.getUrl())
          .append(endpoint.getUrl().contains("?") ? '&' : '?')
          .append(getAuthQuery(endpoint.getAlias()))
          .append("&openid.return_to=")
          .append(returnToUrlEncode)
          .append("&openid.assoc_handle=")

这是我的getAuthQuery 函数

 String getAuthQuery(String axa) {
        if (authQuery!=null)
            return authQuery;
        List<String> list = new ArrayList<String>();
        list.add("openid.ns=http://specs.openid.net/auth/2.0");
        list.add("openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select");
        list.add("openid.identity=http://specs.openid.net/auth/2.0/identifier_select");
        list.add("openid.mode=checkid_setup");
        list.add("openid.ns." + axa + "=http://openid.net/srv/ax/1.0");
        list.add("openid." + axa + ".mode=fetch_request");
        list.add("openid." + axa + ".type.email=http://axschema.org/contact/email");
        list.add("openid." + axa + ".type.fullname=http://axschema.org/namePerson");
        list.add("openid." + axa + ".type.language=http://axschema.org/pref/language");
        list.add("openid." + axa + ".type.firstname=http://axschema.org/namePerson/first");
        list.add("openid." + axa + ".type.lastname=http://axschema.org/namePerson/last");
        list.add("openid." + axa + ".type.gender=http://axschema.org/person/gender");
        list.add("openid." + axa + ".required=email,fullname,language,firstname,lastname,gender");
        String query = Utils.buildQuery(list);
        authQuery = query;
        return query;
    }

希望这能让您了解如何使用属性交换。

【讨论】:

  • 非常感谢!除了您的代码之外,这个replacement 还帮助解决了我的问题。 :)
猜你喜欢
  • 2018-06-25
  • 1970-01-01
  • 2021-09-07
  • 2010-09-06
  • 2014-04-30
  • 2011-12-04
  • 2012-12-22
  • 1970-01-01
  • 2011-05-30
相关资源
最近更新 更多