gpt4 book ai didi

active-directory - Azure 事件目录 : Get user's UPN with OpenID Connect authentication

转载 作者:行者123 更新时间:2023-12-01 01:00:04 26 4
gpt4 key购买 nike

我希望 ASP.Net MVC 5 网站的登录系统由 Azure Active Directory 支持。

具体来说,我想知道用户是否是特定组的成员并基于此授予访问权限。

我有代码来查询 AD 中的用户/组,只有来自 AD 的用户才能通过 Microsoft 的身份验证并重定向到网站。

但似乎我需要用户的主体名称(UPN、ClaimTypes.Upn)来查询 Azure AD 图形 API,而 OpenID Connect Provider 只是给了我一些版本的用户电子邮件地址:

从 OpenID 连接:
User.Identity.Name = live.com#timm@domain.tld
来自 AD Graph API:
user.UserPrincipalName = timm_domain#EXT@something.onmicrosoft.com
是否有可能获取内部用户 GUID 或从一个 ID 获取到另一个 ID,以便能够查询当前用户的 AD 图形 API?

最佳答案

的确。从 objectidentifier 声明中获取用户的 ObjectId,使用:

ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value



默认情况下为常规组织帐户设置 UPN 属性 - 而您以 MSA(Microsoft 帐户)外部用户身份进行签名。默认情况下,MSA 外部用户没有设置 UPN 属性。也就是说,您不需要用户的 UPN 来使用 Graph API 查询他们的组成员资格 - 建议使用 ObjectId。此外,我们建议您出于授权目的使用 getMemberGroup返回用户的可传递组成员身份的 API。

希望这可以帮助。

有关其他声明类型的引用:Azure AD 为 MSA 外部用户颁发的原始 JWT 访问 token 如下所示:
{
"family_name": "Guest",
"unique_name": "Live.com#aadguest@outlook.com",
"altsecid": "1:Live.com:00034001C80D80E9",
"ver": "1.0",
"aud": "https://graph.windows.net",
"acr": "1",
"iss": "https://sts.windows.net/62e173e9-301e-423e-bcd4-29121ec1aa24/",
"oid": "fa6fa59a-5f2b-4069-a8e4-c76e52179f64",
"scp": "Directory.Read UserProfile.Read",
"idp": "Live.com",
"email": "aadguest@outlook.com",
"appidacr": "1",
"given_name": "AAD",
"exp": 1403260411,
"appid": "29181964-d91b-4331-859d-d815863848d6",
"tid": "62e173e9-301e-423e-bcd4-29121ec1aa24",
"iat": 1403256511,
"amr": [
"pwd"
],
"nbf": 1403256511,
"sub": "Wi6CVQ6FVj_aj3na076wm-C6eJy6CK6YhB3PR9Jpty0"
}

关于active-directory - Azure 事件目录 : Get user's UPN with OpenID Connect authentication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24290154/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com