Asp.Net Core Twitch OAuth: Correlation Failed

403 views Asked by At

I configured Twitch authentication for my website using this tutorial: https://blog.elmah.io/cookie-authentication-with-social-providers-in-asp-net-core/ In the Twitch dev console I added the https://localhost:44348/signin-twitch url to the callback urls. I've implemented oauth for other providers before, but having troubles with Twitch.

When I try to login, I get the Twitch authorization screen, but after clicking 'Authorize' it redirects me to /signin-twitch + params which returns a Correlation Failed exception. Exception: An error was encountered while handling the remote login. enter image description here

I have a feeling it might have to do with the routing. It's setup like this because I have a frontend application with it's own routing (hence the Fallback)

Here is all relevant code.

public void ConfigureServices(IServiceCollection services)
{
        ...
        services.AddAuthentication(options =>
        {
            options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        })
        .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
        {
            options.LoginPath = "/signin";
            options.LogoutPath = "/signout";
        })
        .AddTwitch(TwitchAuthenticationDefaults.AuthenticationScheme, options =>
        {
            options.ClientId = "xxx";
            options.ClientSecret = "xxx";
            options.Scope.Add("user:read:email");
            options.SaveTokens = true;
            options.AccessDeniedPath = "/";
        });
}
  
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...

    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
        endpoints.MapFallbackToController("Index", "Home");
    });
}
    public class AuthenticationController : Controller
    {

        [HttpGet("~/signin")]
        public IActionResult SignIn(string returnUrl = "")
        {
            return Challenge(TwitchAuthenticationDefaults.AuthenticationScheme);
        }
    }

1

There are 1 answers

0
iamdlm On

I think that the error occurs because you're trying to access the URL which is assigned as Callback Path.

Try some variant of this:

[HttpGet("~/signin")]
public IActionResult SignIn()
{
    var authProperties = _signInManager
        .ConfigureExternalAuthenticationProperties("Twitch",
        Url.Action("LoggingIn", "Account", null, Request.Scheme));

    return Challenge(authProperties, "Twitch");
}

Source: this answer and this one.

Other stuff to check:

  • Multiple clients with the same Callback Path
  • CookiePolicyOptions
  • HTTPS redirect