我正在使用 Azure AD 在 Azure Web 应用程序中进行身份验证。虽然我可以通过 /.auth/me 端点客户端访问用户信息,但出于安全原因,我需要在服务器端获取用户组成员身份。如何在 Azure Web Apps 中的服务器端检索此信息?
我同意@Dai,在Azure Web App环境中,直接在服务器端检索Azure AD用户组信息是不可行的。您需要使用 Microsoft Graph API。
因此,通过调用以下 Microsoft Graph API 查询来修改代码以检索登录用户的组成员身份:
GET https://graph.microsoft.com/v1.0/me/transitiveMemberOf/microsoft.graph.group
transitiveMemberOf
返回与组嵌套相关的组如果您想获取群组用户是的直接成员,请使用以下查询:
GET https://graph.microsoft.com/v1.0/me/memberOf/microsoft.graph.group
确保向 Microsoft Entra ID 应用程序授予
GroupMember.Read.All
API 权限。
参考资料:
列出用户的直接成员资格 - Microsoft Graph v1.0 |微软
active-directory-aspnetcore-webapp-openidconnect-v2/2-WebApp-graph-user (github.com)