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


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和国家等属性?如何在URL中添加以下参数?

<>以前openid.ext1。模式 fetch_requestopenid.ext1。需要国家,电子邮件、firstname、lastname、语言openid.ext1.type。国家http://axschema.org/contact/country/homeopenid.ext1.type。电子邮件http://axschema.org/contact/emailopenid.ext1.type。firstname http://axschema.org/namePerson/firstopenid.ext1.type。语言http://axschema.org/pref/languageopenid.ext1.type。lastname http://axschema.org/namePerson/openid.ns。ext1 http://openid.net/srv/ax/1.0

您需要在调用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");

相关内容

  • 没有找到相关文章

最新更新