首页 > 解决方案 > 0365 身份验证.NET CORE

问题描述

我知道 Azure Active Directory,但不确定从哪里开始......或者它是否是最佳选择。

我有一个 .NET 核心应用程序(部署到 Azure WebApp)。我想用 o365 auth 保护这个应用程序。当此人登录后,我需要能够基于令牌跟踪对 API 的每个请求。

我不确定这是否像听起来那么简单——是吗?

谢谢你。

标签: .net-coreazure-active-directoryazure-web-app-serviceoffice365apihttp-token-authentication

解决方案


设法回答了我自己的问题。假设此人已通过 O365 进行身份验证:

var identity = ((ClaimsIdentity)HttpContext.User.Identity);
var name = identity.Claims.FirstOrDefault(c => c.Type == "name")?.Value;
var email = identity.Claims.FirstOrDefault(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;

推荐阅读