且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET Core 2.0 MVC应用程序的HomeController中获取当前的外部提供程序

更新时间:2021-07-10 23:33:51

使用外部提供程序登录时,SignInManager将类型为http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod的声明添加到ClaimsPrincipal(

When signing in using an external provider, SignInManager adds a claim of type http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod to the ClaimsPrincipal (source). You can read this value to determine which provider was used for sign-in.

下面是一些示例代码,您应该可以直接将它们插入HomeController:

Here's some example code that you should be able to plug in to your HomeController as is:

var externalProvider = User.FindFirstValue(ClaimTypes.AuthenticationMethod);