Skip to content

Commit 4b822c1

Browse files
zAfLukevinchalet
authored andcommitted
Introduce a force_verify option in the Twitch provider
1 parent fa0b177 commit 4b822c1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/AspNet.Security.OAuth.Twitch/TwitchAuthenticationHandler.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* for more information concerning the license and the contributors participating to this project.
55
*/
66

7+
using System.Collections.Generic;
78
using System.Net.Http;
89
using System.Net.Http.Headers;
910
using System.Security.Claims;
@@ -13,6 +14,7 @@
1314
using Microsoft.AspNetCore.Authentication;
1415
using Microsoft.AspNetCore.Authentication.OAuth;
1516
using Microsoft.AspNetCore.Http.Authentication;
17+
using Microsoft.AspNetCore.WebUtilities;
1618
using Microsoft.Extensions.Logging;
1719
using Newtonsoft.Json.Linq;
1820
using static AspNet.Security.OAuth.Twitch.TwitchAuthenticationConstants;
@@ -26,6 +28,17 @@ public TwitchAuthenticationHandler([NotNull] HttpClient client)
2628
{
2729
}
2830

31+
protected override string BuildChallengeUrl(AuthenticationProperties properties, string redirectUri)
32+
=> QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, new Dictionary<string, string>
33+
{
34+
["client_id"] = Options.ClientId,
35+
["scope"] = FormatScope(),
36+
["response_type"] = "code",
37+
["redirect_uri"] = redirectUri,
38+
["state"] = Options.StateDataFormat.Protect(properties),
39+
["force_verify"] = Options.ForceVerify ? "true" : "false"
40+
});
41+
2942
protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull] ClaimsIdentity identity,
3043
[NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens)
3144
{

src/AspNet.Security.OAuth.Twitch/TwitchAuthenticationOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,12 @@ public TwitchAuthenticationOptions()
2828

2929
Scope.Add("user:read:email");
3030
}
31+
32+
/// <summary>
33+
/// Gets or sets a boolean indicating whether the "force_verify=true" flag should be sent to Twitch.
34+
/// When set to <c>true</c>, Twitch displays the consent screen for every authorization request.
35+
/// When left to <c>false</c>, the consent screen is skipped if the user is already logged in.
36+
/// </summary>
37+
public bool ForceVerify { get; set; }
3138
}
3239
}

0 commit comments

Comments
 (0)