Skip to content

Commit adfec31

Browse files
committed
Add Prompt Options for Request Authorization
1 parent d8ff723 commit adfec31

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

GoogleApis.Blazor/AllEnums.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ public enum EventValueType
6969
Location,
7070
}
7171

72+
public enum PromptType
73+
{
74+
[Description("none")]
75+
None,
76+
[Description("consent")]
77+
Consent,
78+
[Description("select_account")]
79+
SelectAccount,
80+
}
81+
7282
}

GoogleApis.Blazor/Auth/AuthService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ public AuthService(IJSRuntime jsRuntime, IHttpClientFactory httpClientFactory, I
3737
}
3838

3939
/// <summary>
40-
/// oAuth2 Step 1. Opens "Select Google Account" page in a new tab and return the value into redirectUrl.
40+
/// oAuth2 Step 1. Opens "Select Google Account" page in a new tab and return the value into redirectUrl. Default prompt is consent, which asked for user permission each time (none for not opening consent page and select account for account select account page).
4141
/// </summary>
4242
/// <param name="clientId"></param>
4343
/// <param name="scopes"></param>
4444
/// <param name="redirectUrl"></param>
45+
/// <param name="promptType"></param>
4546
/// <returns></returns>
46-
public async Task RequestAuthorizationCode(string clientId, List<Scope> scopes, string redirectUrl)
47+
public async Task RequestAuthorizationCode(string clientId, List<Scope> scopes, string redirectUrl, PromptType promptType = PromptType.Consent)
4748
{
4849
string encodedRedirectUrl = HttpUtility.UrlEncode(redirectUrl);
4950
if (scopes == null || scopes.Count == 0)
@@ -57,7 +58,7 @@ public async Task RequestAuthorizationCode(string clientId, List<Scope> scopes,
5758
}
5859
string scopeString = string.Join("+", scopeStringList);
5960

60-
await JSRuntime.InvokeAsync<object>("open", $"https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?response_type=code&client_id={clientId}&scope={scopeString}&redirect_uri={encodedRedirectUrl}&flowName=GeneralOAuthFlow&access_type=offline&prompt=consent", "_blank");
61+
await JSRuntime.InvokeAsync<object>("open", $"https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?response_type=code&client_id={clientId}&scope={scopeString}&redirect_uri={encodedRedirectUrl}&flowName=GeneralOAuthFlow&access_type=offline&prompt={promptType.ToDescriptionString()}", "_blank");
6162
}
6263

6364
/// <summary>

0 commit comments

Comments
 (0)