Closed RebelEcheveria closed 1 year ago
Fixed by adding Cookie authentication and setting it as the default authentication scheme.
Note: this stupid bug was introduced in .NET 7.0 when the ASP.NET team decided to always default to the single authentication handler available when only one is registered in the pipeline: in this case, the Discord handler tries to delegate the persistence of the user identity to another handler, but the ASP.NET Core authentication stack doesn't find one and returns the only handler available: Discord. It does that until it stack-overflows... 🤣
If you don't need to persist the user identity in a cookie (e.g you just want to perform a one-shot action on behalf of the user after he approves the connection), the OpenIddict client and its Discord integration won't require registering a cookie handler. You can learn more about the OpenIddict providers here: https://kevinchalet.com/2022/12/16/getting-started-with-the-openiddict-web-providers/
Describe the bug
Adding the Discord OAuth Provider as described at https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/blob/dev/docs/discord.md causes a StackOverflowException to be thrown when a request is made.
Steps To reproduce
Create a default .NET 7 webapi project using
dotnet new webapi
and add theAspNet.Security.OAuth.Discord
package to it.Add the following code to the Program.cs file:
Add
app.UseAuthentication();
right above theapp.UseAuthorization();
line.Start the app using
dotnet run
and open the URL that it starts up on.Expected behaviour
The app should work normally.
Actual behaviour
A StackOverflowException is thrown with a very long stack trace, the first 100 lines of which are included below.
System information
OS: Windows 10 Library Version: 7.0.2 .NET Version: 7.0.100
Additional context
First 100 lines of the stack trace: