Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit ddeef1f

Browse files
committed
Add prompt parameter to Google auth endpoint
1 parent 5aae7de commit ddeef1f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Microsoft.AspNetCore.Authentication.Google/GoogleHandler.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,20 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
8787
// TODO: Abstract this properties override pattern into the base class?
8888
protected override string BuildChallengeUrl(AuthenticationProperties properties, string redirectUri)
8989
{
90-
var scope = FormatScope();
90+
// Google Identity Platform Manual:
91+
// https://developers.google.com/identity/protocols/OAuth2WebServer
9192

9293
var queryStrings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
9394
queryStrings.Add("response_type", "code");
9495
queryStrings.Add("client_id", Options.ClientId);
9596
queryStrings.Add("redirect_uri", redirectUri);
9697

97-
AddQueryString(queryStrings, properties, "scope", scope);
98-
98+
AddQueryString(queryStrings, properties, "scope", FormatScope());
9999
AddQueryString(queryStrings, properties, "access_type", Options.AccessType);
100100
AddQueryString(queryStrings, properties, "approval_prompt");
101+
AddQueryString(queryStrings, properties, "prompt");
101102
AddQueryString(queryStrings, properties, "login_hint");
103+
AddQueryString(queryStrings, properties, "include_granted_scopes");
102104

103105
var state = Options.StateDataFormat.Protect(properties);
104106
queryStrings.Add("state", state);

test/Microsoft.AspNetCore.Authentication.Test/Google/GoogleMiddlewareTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ public async Task ChallengeWillTriggerRedirection()
4343
Assert.Contains("&state=", location);
4444

4545
Assert.DoesNotContain("access_type=", location);
46+
Assert.DoesNotContain("prompt=", location);
4647
Assert.DoesNotContain("approval_prompt=", location);
4748
Assert.DoesNotContain("login_hint=", location);
49+
Assert.DoesNotContain("include_granted_scopes=", location);
4850
}
4951

5052
[Fact]
@@ -177,7 +179,9 @@ public async Task ChallengeWillUseAuthenticationPropertiesAsParameters()
177179
{ "scope", "https://www.googleapis.com/auth/plus.login" },
178180
{ "access_type", "offline" },
179181
{ "approval_prompt", "force" },
180-
{ "login_hint", "test@example.com" }
182+
{ "prompt", "consent" },
183+
{ "login_hint", "test@example.com" },
184+
{ "include_granted_scopes", "false" }
181185
}));
182186
}
183187

@@ -189,6 +193,8 @@ public async Task ChallengeWillUseAuthenticationPropertiesAsParameters()
189193
Assert.Contains("scope=" + UrlEncoder.Default.Encode("https://www.googleapis.com/auth/plus.login"), query);
190194
Assert.Contains("access_type=offline", query);
191195
Assert.Contains("approval_prompt=force", query);
196+
Assert.Contains("prompt=consent", query);
197+
Assert.Contains("include_granted_scopes=false", query);
192198
Assert.Contains("login_hint=" + UrlEncoder.Default.Encode("test@example.com"), query);
193199
}
194200

0 commit comments

Comments
 (0)