用 Net::OpenID::Consumer 取得 Google 的帳戶資料

GoogleOpenID 服務有提供 OpenID Attribute Exchange 1.0 (參考「Federated Login for Google Account Users」這個網頁), 測了一陣子才知道要怎麼透過 PerlNet::OpenID::Consumer 取得資料:

my $csr = Net::OpenID::Consumer->new(
    ua => LWPx::ParanoidAgent->new,
    args => {},
    consumer_secret => 'secret',
    required_root => 'http://.../',
    minimum_version => 2
);

my $claimed_identity = $csr->claimed_identity('https://www.google.com/accounts/o8/id');

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

my $check_url = $claimed_identity->check_url(
    delayed_return => 1,
    return_to => 'http://.../...',
    trust_root => 'http://.../'
);

say $check_url;

之前會試不出來,主要是卡在 type.email 忘記加,加上去的時候又打成 email...

Leave a Reply

Your email address will not be published. Required fields are marked *