Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:50:46+00:00 2026-05-25T02:50:46+00:00

According to this documentation , process of receiving OAuth access token is straightforward. I

  • 0

According to this documentation, process of receiving OAuth access token is straightforward. I would like to see a list of all available API endpoints that is ready to accept OAuth 2.0 access token. But for my current needs i would like to somehow receive username and email of a user using OAuth 2.0 access token.

I successfully can receive, for example, data from this endpoint:

https://www.google.com/m8/feeds/contacts/default/full

But unable to receive data from this endpoint:

https://www.googleapis.com/userinfo/email

I tried both header-base and querystring-base approaches of passing single access token. Here is a header i tried:

Authorization: OAuth My_ACCESS_TOKEN

And I even tried OAuth 1.0 version of Authorization header, but… in OAuth 2.0 we do not have secret access token, for instance. Google use bearer tokens in his implementation of OAuth 2.0, so no additional credentials are required.

Anyone successfully received username and email using Google OAuth 2.0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:50:47+00:00Added an answer on May 25, 2026 at 2:50 am

    I found the answer I was looking for. I had to convert PHP to MVC, but pretty easy:

    http://codecri.me/case/430/get-a-users-google-email-address-via-oauth2-in-php/

    My MVC Login sandbox code looks like the following.
    (using JSON.Net http://json.codeplex.com/)

    public ActionResult Login()
        {
            string url = "https://accounts.google.com/o/oauth2/auth?";
            url += "client_id=<google-clientid>";
            url += "&redirect_uri=" +
              // Development Server :P 
              HttpUtility.UrlEncode("http://localhost:61857/Account/OAuthVerify");
            url += "&scope=";
            url += HttpUtility.UrlEncode("http://www.google.com/calendar/feeds/ ");
            url += HttpUtility.UrlEncode("http://www.google.com/m8/feeds/ ");
            url += HttpUtility.UrlEncode("http://docs.google.com/feeds/ ");
            url += HttpUtility.UrlEncode("https://mail.google.com/mail/feed/atom ");
            url += HttpUtility.UrlEncode("https://www.googleapis.com/auth/userinfo.email ");
            url += HttpUtility.UrlEncode("https://www.googleapis.com/auth/userinfo.profile ");
            url += "&response_type=code";
    
            return new RedirectResult(url);
        }
    

    The code returned is proof of Authorization token from the user, which then needs to be turn into a Authentication (accessToken) to access resources.
    My MVC OAuthVerify then looks like:

        public ActionResult AgentVerify(string code)
        {
            JObject json;
    
            if (!string.IsNullOrWhiteSpace(code))
            {
                NameValueCollection postData = new NameValueCollection();
                postData.Add("code", code);
                postData.Add("client_id", "<google-clientid>");
                postData.Add("client_secret", "<google-client-secret>");
                postData.Add("redirect_uri", "http://localhost:61857/Account/OAuthVerify");
                postData.Add("grant_type", "authorization_code");
    
                try
                {   
                    json = JObject.Parse(
                      HttpClient.PostUrl(
                        new Uri("https://accounts.google.com/o/oauth2/token"), postData));
                    string accessToken = json["access_token"].ToString();
                    string refreshToken = json["refresh_token"].ToString();
                    bool isBearer = 
                      string.Compare(json["token_type"].ToString(), 
                                     "Bearer", 
                                     true, 
                                     CultureInfo.CurrentCulture) == 0;
    
                    if (isBearer)
                    {
                        json = JObject.Parse(
                          HttpClient.GetUrl(
                            new Uri("https://www.googleapis.com/oauth2/v1/userinfo?alt=json"),
                          accessToken));
                        string userEmail = json["email"].ToString();
                    }
                    return View("LoginGood"); 
                }
                catch (Exception ex)
                {
                    ErrorSignal.FromCurrentContext().Raise(ex); //ELMAH
                }
            }
            return View("LoginBad");
        }
    

    To complete how everything works, I’ve included the HttpClient utility I created in case anyone needed it.

    public class HttpClient
    {
        public static string GetUrl(Uri url, string OAuth)
        {
            string result = string.Empty;
    
            using (WebClient httpClient = new WebClient())
            {
                httpClient.Headers.Add("Authorization","OAuth " + OAuth);
                result = httpClient.DownloadString(url.AbsoluteUri);
            }
    
            return result;
        }
    
        public static string PostUrl(Uri url, NameValueCollection formData)
        {
            string result = string.Empty;
    
            using (WebClient httpClient = new WebClient())
            {
                byte[] bytes = httpClient.UploadValues(url.AbsoluteUri, "POST", formData);
                result = Encoding.UTF8.GetString(bytes);
            }
    
            return result;
        }
    }
    

    Again, this is test code just to get it to function, I do not recommend using this as-is in a production environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get an access_token according to this documentation http://dev.twitter.com/doc/post/oauth/request_token . I use
I'm using TinyXML to parse/build XML files. Now, according to the documentation this library
According to the MySQL documentation regarding Optimizing Queries With Explain : * ALL: A
According to this documentation http://www.cplusplus.com/reference/clibrary/ctime/time/ for time(NULL) If the function could not retrieve the
I would like to directly see the output of a command started by the
According to this documentation, http://jqueryui.com/demos/datepicker/#option-altFormat I can set a different date format for the
According to the documentation this should just work but it certainly isn't for me.
According to this section of the Hibernate documentation I should be able to query
According to this answer or the android's documentation there is several ways to get
According to this documentation ( http://java.sun.com/docs/books/jls/third_edition/html/lexical.html , 3.10.6) an OctalEscape will be converted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.