Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require Google to return email address as part of OAuth

I am using OAuth to access Gmail with dotNetOAuth. How can I force Google to return user's email address as part of callback after authorization?

By default, Google OAuth callback only returns the token secret and access tokens.

like image 537
Khash Avatar asked Jun 27 '10 21:06

Khash


People also ask

Does Gmail require OAuth?

All requests to the Gmail API must be authorized by an authenticated user. Gmail uses the OAuth 2.0 protocol for authenticating a Google account and authorizing access to user data. You can also use Google Sign-in to provide a "sign-in with Google" authentication method for your app.

How do I get my Google access token email API?

If this scope is included while you generate the refresh token, you should be able to get the email address of the authenticating user by making the following request: https://www.googleapis.com/oauth2/v2/userinfo?access_token="YOUR_ACCESS_TOKEN". You can try this out in the API explorer.

How to get user's email from Google using OAuth?

For signing in with Google using OAuth 2.0, there's no need to make a separate request to get user's email. When Google calls the callback URL, it provides a code in the query string that you could use to exchange for access token and ID token.

What version of OAuth does Google use?

Note: Use of Google's implementation of OAuth 2.0 is governed by the OAuth 2.0 Policies. Google APIs use the OAuth 2.0 protocol for authentication and authorization.

How do I obtain OAuth credentials from the Google API console?

Obtain OAuth 2.0 credentials from the Google API Console. Visit the Google API Console to obtain OAuth 2.0 credentials such as a client ID and client secret that are known to both Google and your application. The set of values varies based on what type of application you are building.

How does Google verify OAuth authentication?

When you use OAuth 2.0 for authentication, your users are authenticated after they agree to terms that are presented to them on a user consent screen. Google verifies public applications that use OAuth 2.0 and meet one or more of the verification criteria. Learn more about public versus internal applications below.


1 Answers

First you need to add the following scope (https://www.googleapis.com/auth/userinfo.email) to your oauth request.

After you're back to your app from Google and you have your access token, you can make a request using the access token to https://www.googleapis.com/userinfo/email?alt=json. This will return the email address. More info at http://sites.google.com/site/oauthgoog/Home/emaildisplayscope

like image 54
mergoc Avatar answered Nov 13 '22 12:11

mergoc