azure - 有没有办法将一个 AzureAD 应用程序同时用于前端和后端

标签 azure azure-active-directory azure-ad-graph-api

我有 React 前端应用程序和 AWS lambda 后端。我已经使用 MSAL 将 AzureAD 身份验证集成到我的 React 应用程序中。我想澄清一些事情

  • 用户登录前端后,我想调用我的后端 API 之一,并通过我的后端服务调用 azure graph api。对于后端 azure 交互,我必须在 azure 广告中创建另一个应用程序。我的问题是,我可以使用我的前端访问 token 来调用 azure graph api,因为我的前端访问 token 属于 azure 广告中的不同应用程序?如果不是,建议的方式是什么来进行这种流程?

  • 有什么方法可以将admin、manager、user等用户角色添加到事件目录中,并在用户登录时检索该角色。我的要求是用户登录后我需要根据角色向我的前端应用程序显示某些功能。我看到有一些叫做范围的东西,但无法弄清楚它是否满足我的要求。

最佳答案

我尝试在我的环境中重现相同的结果,并得到如下结果:

您必须创建两个 Azure AD 应用程序进行身份验证。

我创建了 Azure AD ServerApp 并公开了如下所示的 API:

enter image description here

Is there any way to add the user role like admin, manager, user to the active directory and retrieve that role when the user logs in.

ServerApp中,我创建了应用程序角色:

enter image description here

现在,在 ClientApp 中,我添加了 API 权限,如下所示:

enter image description here

enter image description here

现在,我使用以下参数通过客户端凭据流生成了访问 token :

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
client_secret:ClientSecret
scope:api://SeverAppID/.default
grant_type:client_credentials

enter image description here

当我解码 token 时,应用程序角色成功显示,如下所示:

enter image description here

关于azure - 有没有办法将一个 AzureAD 应用程序同时用于前端和后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75878593/

相关文章:

c# - 具有 if-else 条件的 Azure Bot 对话框

wpf - Azure 应用程序注册中的用户分配

azure - MSAL - 使用 IntegratedWindowsAuth 获取 token 时出现问题

oauth-2.0 - Microsoft Graph API Authentication_MissingOrMalformed

c# - 如何在azure上上传图像列表并检索已上传图像的地址

node.js - BotFramework WebChat 未接收消息。

linux - Ansible azure 模块 azure.azcollection.azure_rm_adgroup_info 的 Azure AD 应用程序权限

javascript - azure-graph 产生 Request_BadRequest : Invalid domain name in the request url

azure - Azure HDInsight 边缘节点上的 ssh

Azure B2C 自定义策略 - ID/访问 token 未通过刷新 token 获取最新声明