使用Net :: OpenID :: Consumer进行属性交换

时间:2013-05-18 12:17:29

标签: perl openid perl-module mod-perl2

my $csr = Net::OpenID::Consumer->new(
    ua              => LWP::UserAgent->new,
    consumer_secret => '123456xXx',
    required_root   => "http://www.myopenidsample.net/",
  );

my $openid = "https://me.yahoo.com";

my $claimed_id = $csr->claimed_identity($openid);

if ($claimed_id){
    my $check_url = $claimed_id->check_url(
        delayed_return => 1,
        return_to      => "http://www.myopenidsample.net/response.cgi",
        trust_root     => "http://www.myopenidsample.net/",
      );

    print $q->redirect($check_url);
}

如何获取电子邮件,firstName,lastName和country等属性? 如何将以下参数附加到URL?

openid.ext1.mode            fetch_request
openid.ext1.required        country,email,firstname,lastname,language
openid.ext1.type.country    http://axschema.org/contact/country/home
openid.ext1.type.email      http://axschema.org/contact/email
openid.ext1.type.firstname  http://axschema.org/namePerson/first
openid.ext1.type.language   http://axschema.org/pref/language
openid.ext1.type.lastname   http://axschema.org/namePerson/
openid.ns.ext1              http://openid.net/srv/ax/1.0

1 个答案:

答案 0 :(得分:1)

您需要在调用check_url之前添加以下代码(该示例已通过Google测试以便仅获取电子邮件):

    $claimed_id->set_extension_args(
    "http://openid.net/srv/ax/1.0",
      {
        'mode' => 'fetch_request',
        'type.email' => 'http://axschema.org/contact/email',
        'required'   => 'email',
      });

要在回报中获取值,我使用:

    my $email = $csr->message->get_ext
         ("http://openid.net/srv/ax/1.0", "value.email");