0
votes

I was testing around with Google's oauth and was trying out different scopes.

However, I then reduced my scope request to just this : "https://www.googleapis.com/auth/userinfo.email"

The following is more in dotnetcore

  Dictionary<string, string> queries = new Dictionary<string, string>();
            queries.Add("scope", "https://www.googleapis.com/auth/userinfo.email");
            queries.Add("access_type", "offline");
            queries.Add("include_granted_scopes" ,"true");
            queries.Add("response_type", "code");
            queries.Add("state", "state");
            queries.Add("redirect_uri", "http://localhost:5000/api/authenticate/googauth");
            queries.Add("client_id", _clientId);
            queries.Add("prompt", "consent");

            UriBuilder builder = new UriBuilder();
            builder.Host = "accounts.google.com";
            builder.Scheme = "https";
            builder.Path = "o/oauth2/v2/auth";
            //builder.Query = ""

            foreach (var query in queries)
            {
                if (string.IsNullOrEmpty(builder.Query))
                {
                    builder.Query += $"{query.Key}={query.Value}";
                }
                else
                {
                    builder.Query += $"&{query.Key}={query.Value}";
                }
            }

            var redirectUri = builder.Uri.ToString();

            return Redirect(redirectUri);

From the returned code, I then retrieved the access token etc.

   Dictionary<string, string> values = new Dictionary<string, string>();
            values.Add("code", code);
            values.Add("client_id", _clientId);
            values.Add("client_secret",_clientSecret);
            values.Add("redirect_uri", "http://localhost:5000/api/authenticate/googauth");
            values.Add("grant_type", "authorization_code");

            var client = new HttpClient();
            var result = await client.PostAsync("https://oauth2.googleapis.com/token", new FormUrlEncodedContent(values));
            var content = await result.Content.ReadAsStringAsync();
            var convertedContent = JsonSerializer.Deserialize<GoogleAccesstoken>(content);

However, I seem to get more than what I asked for. I get this in the returned scopes :

openid https://www.googleapis.com/auth/user.gender.read https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/user.birthday.read

I've tried using incognito, and different browsers and they all return the same thing (thinking that it may have been a cache issue).

Is anyone able to help me on this?

Thanks.

1

1 Answers

2
votes

Enables applications to use incremental authorization to request access to additional scopes in context. If you set this parameter's value to true and the authorization request is granted, then the new access token will also cover any scopes to which the user previously granted the application access. See the incremental authorization section for examples.

extract from google documentation: https://developers.google.com/identity/protocols/oauth2/web-server

Basically means that the user has previously granted you the other scopes. Could have been through a login screen or something where you have used the same clientId