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

问题描述 投票:0回答:2

我一直在尝试使用 Bing Ads API,但连第一步都无法完成。我已严格按照这些步骤进行操作,但我陷入了需要征求用户同意的部分。

我创建了一个应用程序,并复制了所有详细信息。我创建了一个如下所示的 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(Microsoft+Advertising+API+Service)+that+your+organization+%27xxxxxxx7+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.%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 azure-active-directory bing-ads-api azure-oauth microsoft-oauth
2个回答
4
投票

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

我注册了一个 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

解决错误,您需要添加

msads.manage
Microsoft Advertising API Service的权限。

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

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

使用上面的代码,您可以为您的应用程序生成访问令牌。


0
投票

Microsoft Ads 是否需要验证,还是因为我们仍然无法访问该服务而没有必要?

© www.soinside.com 2019 - 2024. All rights reserved.