Skip to content

Commit 1909b75

Browse files
zAfLukevinchalet
authored andcommitted
Introduce a force_verify option in the Twitch provider
1 parent 04566ab commit 1909b75

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ We would love it if you could help contributing to this repository.
6060
* [Tathagata Chakraborty](https://github.com/tatx)
6161
* [Tommy Parnell](https://github.com/tparnell8)
6262
* [Yannic Smeets](https://github.com/yannicsmeets)
63+
* [zAfLu](https://github.com/zAfLu)
6364
* [zhengchun](https://github.com/zhengchun)
6465

6566
## Support

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;
@@ -12,6 +13,7 @@
1213
using JetBrains.Annotations;
1314
using Microsoft.AspNetCore.Authentication;
1415
using Microsoft.AspNetCore.Authentication.OAuth;
16+
using Microsoft.AspNetCore.WebUtilities;
1517
using Microsoft.Extensions.Logging;
1618
using Microsoft.Extensions.Options;
1719
using Newtonsoft.Json.Linq;
@@ -29,6 +31,17 @@ public TwitchAuthenticationHandler(
2931
{
3032
}
3133

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,12 @@ public TwitchAuthenticationOptions()
7373
return user["data"]?[0]?.Value<string>("offline_image_url");
7474
});
7575
}
76+
77+
/// <summary>
78+
/// Gets or sets a boolean indicating whether the "force_verify=true" flag should be sent to Twitch.
79+
/// When set to <c>true</c>, Twitch displays the consent screen for every authorization request.
80+
/// When left to <c>false</c>, the consent screen is skipped if the user is already logged in.
81+
/// </summary>
82+
public bool ForceVerify { get; set; }
7683
}
7784
}

0 commit comments

Comments
 (0)