登录后使用Google身份验证时,User.IsInRole无法正常工作

时间:2017-03-27 15:19:07

标签: asp.net asp.net-mvc asp.net-core asp.net-core-mvc

我看到User.IsInRole周围的几个问题/答案无效,但所有修复都需要手动完成。使用Google身份验证时,只需处理所有内容。

这不起作用:

User.IsInRole( "Admin" )

这确实有效:

var user = await UserManager.GetUserAsync( User );
var isAdmin = await UserManager.IsInRoleAsync( user, "Admin" );

使用Google身份验证使User.IsInRole方案有效时,我该怎么办?

我按照这两个文档来启用Google身份验证。

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/ https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins

1 个答案:

答案 0 :(得分:0)

为了他人的利益而发帖,此后我浪费了整整一个。发生这种情况的原因有两个:

  1. 如果您使用的是CORE 2.1应用程序。
  2. 如果您有自定义声明,则需要确保使用角色感知声明工厂。

Hope this helps.

相关问题