azure - Microsoft/Azure OAuth 失败,我的组织缺少服务主体

标签 azure azure-active-directory bing-ads-api azure-oauth microsoft-oauth

我一直在尝试使用 Bing Ads API,但连第一步都无法完成。我关注了these steps严格来说,但我陷入了需要征求用户同意的部分。

我创建了一个应用程序,并复制了所有详细信息。我创建了一个如下所示的 URL:

https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize
?client_id={client_id}
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost%3A8080
&response_mode=query
&scope=openid%20offline_access%20https%3A%2F%2Fads.microsoft.com%2Fmsads.manage
&state=1234

我还尝试添加 client_secret 作为参数,即使文档中没有提及,但这也不起作用。

但是,我不断收到此错误消息:

error = invalid_client
error_description = AADSTS650052: The app is trying to access a service 'd42ffc93-c136-491d-b4fd-6f18168c68fd'(Microsoft Advertising API Service) that your organization 'xxxxxx' lacks a service principal for. Contact your IT Admin to review the configuration of your service subscriptions or consent to the application in order to create the required service principal.

我刚刚第一次创建了 Azure 帐户(这是我第一次使用 Azure,通常我使用 GCP,很少使用 AWS),而且我是唯一创建过任何内容的帐户。

此错误消息作为附加到重定向 URL 的参数返回,我什至没有进入 Microsoft 登录页面。 (http://localhost:8080/?error=invalid_client&error_description=AADSTS650052%3a+The+app+is+trying+to+access+a+service+%27d42ffc93-c136-491d-b4fd-6f18168c68fd%27(微软+广告+API+服务)+那个+您的+组织+%27xxxxxxx7+缺少+a+服务+主体+。+联系人+您的+IT+管理员+审核+您的+服务+订阅的+配置+或+同意+按+顺序++创建++所需+服务+主体。%0d%0aTrace+ID%3a+387accd1-d7a4-4ec2-b739-6cba07e23702%0d%0aCorrelation+ ID%3a+a7def78f-5c49-4ede-b7d4-fc65d5ac75bc%0d%0aTimestamp%3a+2022-11-10+16%3a15%3a03Z&error_uri=https%3a%2f%2flogin.microsoftonline.com%2ferror%3fcode%3d650052&state= 1234#)

奇怪的是,我同时为客户做了上述同样的事情,并且与他们一起我设法进入了同意页面。

最佳答案

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

我注册了一个 Azure AD 应用程序并授予了 API 权限,如下所示:

enter image description here

为了获取授权码,我在浏览器中执行了与您相同的请求,并在地址栏中收到了如下相同的错误:

https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize
?client_id={client_id}
&response_type=code
&redirect_uri=http://localhost:8080
&response_mode=query
&scope=openid offline_access https://ads.microsoft.com/msads.manage
&state=1234

回应:

enter image description here

为了确认是否是相同的错误,我将其复制到记事本中并检查完整错误,如下所示:

enter image description here

解决该错误,您需要添加Microsoft Advertising API Servicemsads.manage权限。

请注意,您需要拥有Microsoft Advertising 帐户才能使用 Bing Ads API。如果没有,请在此 Microsoft Advertising 注册。使用您的 Azure AD 帐户访问网站,如下所示:

enter image description here

完成注册后,您可以在此处找到Microsoft Advertising API Service:

enter image description here

现在,您可以向您的应用程序添加 msads.manage 权限,如下所示:

enter image description here

现在,当我在浏览器中再次运行授权请求时,我成功获得了同意屏幕,如下所示:

https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize
?client_id={client_id}
&response_type=code
&redirect_uri=http://localhost:8080
&response_mode=query
&scope=openid offline_access https://ads.microsoft.com/msads.manage
&state=1234

回应:

enter image description here

接受同意后,我在地址栏中收到了授权码,如下所示:

enter image description here

使用上述代码,您可以为您的应用程序生成访问 token 。

关于azure - Microsoft/Azure OAuth 失败,我的组织缺少服务主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74392279/

相关文章:

azure - 在 Azure AD 租户的 Azure 门户中将成员作为组所有者添加到组中

azure - 微软图形API : How do I retrieve the assigned groups of an azure user?

Bing 广告 - 上传离线转化数据

php - 如何订阅或启用适用于 Bing Ads 的 Azure 应用程序?

java - 使用服务主体验证存储帐户

azure - 如何在 Azure Service Fabric 中查看跟踪日志记录

python - 在 Azure AD 中创建用户需要哪些应用程序权限?

node.js - 使用 node-soap 连接 Bing Ads API

azure - 将 KeyVault 权限设置为不同租户中的 AAD 应用程序在 PowerShell 中有效,但在 ARM 模板中失败

azure - 如何使用数据工厂截断 Dynamics 365 实体(并复制到 Azure 数据湖)?