c# - 无法在 MVC 应用程序中使用 Microsoft 身份平台授权用户,我正在获取 cookie 但它没有返回用户信息
问题描述
这是单击登录按钮时调用的函数
public void O365Login() {
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
我的重定向 URL 是http://localhost/Home/OfficeLogin
[HttpPost]
public ActionResult OfficeLogin()
{
if (System.Security.Claims.ClaimsPrincipal.Current.FindFirst("preferred_username") != null)
{
UserDetail ud = new UserDetail();
ud.EmailId = System.Security.Claims.ClaimsPrincipal.Current.FindFirst("preferred_username").Value;
//some more items to do after getting the email address
}
return View(ViewBag);
}
到目前为止,这一直运作良好,但本周突然停止运作。
当我用它装饰任何控制器时,[Authorize]
它只会一次又一次地回到 Office 365 登录页面
使用我的 O365 帐户登录后,我每次都会收到一个 cookie,如下所示
OpenIdConnect.nonce.3U+OSOW9r7Hil3ld93kUSryN/mbVs2l2j4kW94KLSOc=
但它没有返回任何用户信息,如姓名/电子邮件等,并且 request.IsAuthorized 仍然是错误的
解决方案
推荐阅读
- android - Flutter 天气应用中的城市选择 - Flutter
- mysql - 合并两张表,使用先进先出排序
- android - 为什么 Android App Links 的自动验证失败
- java - 如何过滤 2 个巨大的列表,其中包含数百万个具有相同 ID 的项目
- image - 如何调整图像大小 woocommerce oceanwp
- python - 安装 pyinstaller 的错误
- c# - 退出时的 Visual Studio Code 会杀死附加了 C# 调试器的外部 .exe 进程
- angular - 在 karma 中测试订阅会给出错误“Observable<>”类型的参数不能分配给“订阅”类型的参数
- image - 将小部件放置在图像内的精确坐标中
- python - UnimplementedError:model.fit() 中不支持将字符串转换为浮点数