【问题标题】:Asp.Net Core Twitch OAuth: Correlation FailedAsp.Net Core Twitch OAuth:关联失败
【发布时间】:2021-08-25 20:48:52
【问题描述】:

我使用本教程为我的网站配置了Twitch authenticationhttps://blog.elmah.io/cookie-authentication-with-social-providers-in-asp-net-core/ 在 Twitch 开发控制台中,我将 https://localhost:44348/signin-twitch url 添加到回调 url。我之前为其他提供商实施过 oauth,但在使用 Twitch 时遇到了麻烦。

当我尝试登录时,我会看到 Twitch 授权屏幕,但在单击“授权”后,它会将我重定向到 /signin-twitch + params,这会返回 Correlation Failed 异常。 Exception: An error was encountered while handling the remote login.

我感觉这可能与路由有关。之所以这样设置,是因为我有一个带有自己路由的前端应用程序(因此是 Fallback)

这里是所有相关代码。

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);
        }
    }

【问题讨论】:

    标签: oauth twitch aspnet-contrib


    【解决方案1】:

    我认为发生错误是因为您尝试访问分配为 Callback Path 的 URL。

    试试这个的一些变体:

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

    来源:this answerthis one

    其他要检查的东西:

    • 具有相同Callback Path 的多个客户端
    • CookiePolicyOptions
    • HTTPS 重定向

    【讨论】:

      猜你喜欢
      • 2018-12-29
      • 2019-07-24
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      相关资源
      最近更新 更多