Get user information from openid

I use lightopenid as the login system for the site and after a successful login I need user data such as his first name, last name, email address and date of birth.

How can I get this information from its openid? Suppose I use an authentication URL for google: https://www.google.com/accounts/o8/id

Then, after the validate () method returns 1, I redirect the user to another page on my site. But how can I get user information after logging in?

FYI, I use openid for google, yahoo and aol. And for facebook, I use the api chart and for twitter, I use twitter oauth. Is there any way to get user data with them? Please suggest.

+4
source share
4 answers

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']; 
+5
source

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

I am adding the following requests to OpenID to receive email information.

 &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 indicates the namespace that is used for extended data.

The second part indicates that we are making a query for the data.

The third part indicates the scheme that we use for email.

And the last part indicates that we demand that the letter be returned.

I tested this with Google and it works great. I do not have other accounts, so I did not check them for them.

OAuth and the Facebook Graph API will have their own formats, so I'm not sure about them.

+1
source
 $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()); 
+1
source

Apparently lightopenid provides a method for this:

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

It returns SimpleReg or Exchange Attribute data. But only if the user has agreed to this, I hope.

0
source

Source: https://habr.com/ru/post/1333483/


All Articles