[英]Asp.Net Core Twitch OAuth: Correlation Failed
我使用本教程為我的網站配置了Twitch 身份驗證: https://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.
我感覺這可能與路由有關。 之所以這樣設置,是因為我有一個帶有自己路由的前端應用程序(因此是后備)
這是所有相關代碼。
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);
}
}
我認為發生錯誤是因為您嘗試訪問分配為Callback Path
的 URL 。
試試這個的一些變體:
[HttpGet("~/signin")]
public IActionResult SignIn()
{
var authProperties = _signInManager
.ConfigureExternalAuthenticationProperties("Twitch",
Url.Action("LoggingIn", "Account", null, Request.Scheme));
return Challenge(authProperties, "Twitch");
}
其他要檢查的東西:
Callback Path
的多個客戶端
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.