English 中文(简体)
Requesting email address from OpenID provider in PHP
原标题:

What s the simplest way to request an email address from an OpenID provider?

Is there a good PHP library that simplifies this problem?

I know that providers implement things differently. I ve heard you need to do both Simple Registration and Attribute Exchange. I d particularly want to make sure that it worked with the biggest providers, such as MyOpenID and Google.

Related, but inadequate, questions:

最佳回答

JanRain has a Open ID PHP Library, one of the first libraries (I believe) from a company centric to OpenID. You mentioned working with MyOpenID, which JanRain s site.

That said, personally I use the Zend Library now (I played with the JanRain library years ago), just because I generally develop using the Zend Framework.

Here are some code examples if the provider uses the OpenID Simple Registration Extension.

This section of the Zend Reference guide shows how to request user information with the authentication request. Here s their example code edited for your needs:

//require e-mail, get nickname and fullname if available
$sreg = new Zend_OpenId_Extension_Sreg(array(
     nickname =>false,
     email =>true,
     fullname =>false), null, 1.1);
$consumer = new Zend_OpenId_Consumer();
if (!$consumer->login($openid, $returnUrl, null, $sreg)) {
    die("OpenID login failed.");
}

Accomplishing the same with the JanRain library is similar, here s some code taken from from the try_auth.php file of the library package (I edited it to show the basic functions you re looking for):

$auth_request = $consumer->begin($openid);
$sreg_request = Auth_OpenID_SRegRequest::build(
                                 // Required
                                 array( email ),
                                 // Optional
                                 array( fullname ,  nickname ));
$auth_request->addExtension($sreg_request);

For Attribute Exchange check out the JanRain Auth_OpenID_AX Classes, in the Zend Library there s a feature request for AX support.

问题回答

I would look at Zend Framework s OpenID Library, Zend_OpenID. You should be able to use it without the entire framework.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签