2
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);
}

如何获取电子邮件、名字、姓氏和国家/地区等属性?如何将以下参数附加到 URL?

openid.ext1.mode fetch_request
openid.ext1. 必需的国家、电子邮件、名字、姓氏、语言
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
4

1 回答 1

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");
于 2013-11-02T22:31:43.767 回答