【发布时间】:2021-08-25 20:48:52
【问题描述】:
我使用本教程为我的网站配置了Twitch authentication: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.
我感觉这可能与路由有关。之所以这样设置,是因为我有一个带有自己路由的前端应用程序(因此是 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