Getting gmail address with ... openid? OAuth?

I'm confused.

I was able to execute openid login using LightOpenID .

All I do is just openid_identity , like " https://www.google.com/accounts/o8/id?id=xxx ". Pretty disappointing: I also expected to get an email address.

i.e. I need to log in (which openid does) and find out the email address of the google account that was used to log in.

There is a function $openid->getAttributes() , but all I get is just an empty array: I think google will not give me anything other than openid_identity .

So, I guess I should use OAuth , right? I do not know about that. I found only terrible and confusing documentation that either pretends to explain everything (and I do means everything), or cannot explain anything at all .

Yes, of course, I tried to look at previous posts about this, just like on Google. Read the above again, please.

+5
source share
4 answers

I just discovered LightOpenID and I think this is great. I managed to get the email address, first and last name and preferred language using the following modification example-gmail.php :

 <?php require_once('openid.php'); if (empty($_GET['openid_mode'])) { if (isset($_GET['login'])) { $openid = new LightOpenID(); $openid->identity = 'https://www.google.com/accounts/o8/id'; $openid->required = array('namePerson/first', 'namePerson/last', 'contact/email', 'pref/language'); header('Location: ' . $openid->authUrl()); //header('Location: ' . str_replace('&amp;', '&', $openid->authUrl())); } else { echo '<form action="?login" method="post">' . "\n"; echo '<button>Login with Google</button>' . "\n"; echo '</form>' . "\n"; } } else if ($_GET['openid_mode'] == 'cancel') { echo 'User has canceled authentication!'; } else { $openid = new LightOpenID(); echo 'User ' . ($openid->validate() ? $_GET['openid_identity'] . ' has ' : 'has not ') . 'logged in.'; echo '<pre>'; print_r($openid->getAttributes()); echo '</pre>'; } ?> 

I modified the code to make it more readable, the output is:

 User https://www.google.com/accounts/o8/id?id=*** has logged in. Array ( [namePerson/first] => Alix [contact/email] => ***@gmail.com [pref/language] => en [namePerson/last] => Axel ) 

I still can’t get the postal code and other Google users, but I had success with myOpenID.com .

+10
source

You can use the exchange of OpenID attributes. See the Google documentation here (specifically openid.ax.type.email ).

+5
source

Having a Google account does not mean that you are getting a gmail account. You can start a Google account with any email address .

Having said that, I don't think its part of the specification returns email addresses or login information as part of the identifier.

+1
source

OAuth and OpenID do not match. They decide completely different things. I agree that you checked: Federated login for users of a Google account , this explains a little more how the accounts for Google Accounts work.

Solutions:

+1
source

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


All Articles