4
votes

I'm using lightopenid as the login system for a site and after successful login, I need the user's details like his first name, last name, email and date of birth..

How can I get this information from his openid? Suppose for google, I'm using the authentication url as: https://www.google.com/accounts/o8/id

Then after the validate() method returns 1, I'm redirecting the user to another page in my site. But how can I fetch the details of the user after login ?

FYI, I'm using openid for google, yahoo and aol. And for facebook, I'm using graph api and for twitter, I'm using twitter oauth. Is there any way of fetching user data with these too? Please suggest.

4
For more details click on this linkFloccinaucinihilipilification.

4 Answers

5
votes

Just read the manual: http://code.google.com/p/lightopenid/wiki/GettingMoreInformation

$openid->required = array('namePerson/friendly', 'contact/email');
$openid->optional = array('namePerson/first');

before calling $openid->authUrl()!

Then

$openid->validate();
$userinfo = $openid->getAttributes();
$email = $userinfo['contact/email'];
$firstName = $userinfo['namePerson/first'];
1
votes

You need to add a parameter to specify that you also want to receive data back from the OpenID request.

I append the following to my OpenID requests to get the email details.

&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ax.mode=fetch_request&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.required=email

The first part specifies the namespace being used for the extended data.

The second part specifies that we are making a fetch request for the data.

The third part specifies the schema we are using for the email.

And the final part is specifying that we require the email to be returned.

I have tested this with Google and it works fine. I do not have the other accounts, so have not tested it for those.

OAuth and Facebook Graph API will have there own formats, so I am not sure on those ones.

1
votes
$openid->identity = 'https://www.google.com/accounts/o8/';

// use the following line to obtain the required details. These are the only details that google mail provides. 
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last');

header('Location: ' . $openid->authUrl());
0
votes

Seemingly lightopenid provides a method for that:

$openid->validate();
$userinfo = $openid->getAttributes();  // associative array

It returns either SimpleReg or "Attribute Exchange" data. But only if the user agreed to that, I would hope.