我目前正在努力使用一个Asp.net core 2应用程序,该应用程序使用两个openid提供程序进行身份验证,并映射到两个不同的身份验证方案(具有不同的名称)。
我面临的问题是尝试注销当前正在使用的特定方案。例如,如果我同时支持Google和Facebook身份验证,则需要了解当前正在使用哪种方案,并调用SignOut
方法来指示正确的方案。这使我可以清除本地cookie,还可以将用户重定向到外部身份提供者并注销。
事实是,我无法找到某种GetCurrentScheme()
函数,因此我可以用来在SignOut
方法中指定方案。我确定我缺少一些基本的知识...
最佳答案
似乎没有任何直接方法可以找到当前方案。这是一种粗略的方法:
private readonly IAuthenticationSchemeProvider authenticationSchemeProvider;
...
foreach(var scheme in authenticationSchemeProvider.GetRequestHandlerSchemesAsync()){
var authResult = await context.AuthenticateAsync(scheme.Name);
if(authResult.Succeeded)
// this is the scheme that was used for authentication
}
关于authentication - 在ASP.NET Core 2中获取当前的身份验证方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54832713/