.net-core - 0365 身份验证.NET CORE
问题描述
我知道 Azure Active Directory,但不确定从哪里开始......或者它是否是最佳选择。
我有一个 .NET 核心应用程序(部署到 Azure WebApp)。我想用 o365 auth 保护这个应用程序。当此人登录后,我需要能够基于令牌跟踪对 API 的每个请求。
我不确定这是否像听起来那么简单——是吗?
谢谢你。
解决方案
设法回答了我自己的问题。假设此人已通过 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;
推荐阅读
- c - 如何理解两个三角形是否不相同但相似?
- node.js - 设置 fs.appendFileSync 的路径?
- sql - COALESCE 函数中的这个 CASE 表达式是多余的吗?
- inno-setup - Inno Setup 无法处理带有空格的源路径
- javascript - 如何仅更新部分状态
- python - 当我添加 PushButtons 时,KeyPressEvent() 不适用于标签
- c++ - Tensorflow 默认如何使用 CPU 内核?
- stm32 - MPU6050 在地址 0x68 上没有响应,但出现在 I2C 扫描地址中
- c# - 使用 PostMessage 模拟鼠标点击
- python-3.x - 如果循环在不需要时重复自身