关于oauth:如何为Azure应用配置同意(AADSTS65005错误)

How to configure consenting for an Azure app (AADSTS65005 error)

我们有一个Azure资源应用程序,我们要公开其API以供Azure上的客户端应用程序访问。这两个应用程序位于不同的租户上。访问API的用户(Office 365帐户持有人)位于不同的租户上。

当我们在租户上手动配置服务主体时,整个设置将起作用,该主体正尝试根据资源应用程序从客户端应用程序进行身份验证。我的意思是,他们能够使用其Office 365帐户登录并显示同意屏幕。

如果我们没有在尝试进行身份验证的用户的AAD租户上提供服务主体,则会出现以下错误:

1
2
3
AADSTS65005 - The app needs access to a service <service> that your
organization org.onmicrosoft.com has not subscribed to or enabled. Contact
your IT Admin to review the configuration of your service subscriptions.

对于我们每个访问我们应用程序(资源应用程序)的租户提供服务主体是不可行的。我们缺少什么吗?我们使用的流量正确吗?


您可以在此处找到针对您的方案的帮助:https://docs.microsoft.com/zh-cn/azure/active-directory/develop/active-directory-devhowto-multi-tenant-overview#understanding-user-和管理员同意。 (向下滚动到多个租户中的多个层)

In the case of an API built by an
organization other than Microsoft, the developer of the API needs to
provide a way for their customers to consent the application into
their customers' tenants.

The recommended design is for the 3rd party
developer to build the API such that it can also function as a web
client to implement sign-up:

  • Follow the earlier sections to ensure
    the API implements the multi-tenant application registration/code
    requirements

  • In addition to exposing the API's scopes/roles, ensure
    the registration includes the"Sign in and read user profile" Azure AD
    permission (provided by default)

  • Implement a sign-in/sign-up page in
    the web client, following the admin consent guidance discussed earlier

  • Once the user consents to the application, the service principal and
    consent delegation links are created in their tenant, and the native
    application can get tokens for the API

  • 基本上,您的应用程序需要的所有部分都必须作为服务主体显示在客户的租户中。这是AAD的要求。

    发生这种情况的唯一方法是让管理员分别对API和应用程序进行同意,因为它们是在不同的租户中注册的。

    如果它们是在同一租户中注册的,则可以使用清单中的knownClientApplications属性,以允许同时同意这两者。


    在我的情况下,我公开了自己的API,并尝试从其他应用程序(客户端凭据模式)访问此API,我删除了该应用程序(使用应用程序和api应用程序)的默认权限-" Azure Active目录图->用户。已读",因为我认为我不需要它,但导致此问题"该应用程序需要访问您的组织尚未订阅或未启用的服务...。请与您的IT管理员联系以进行审核服务订阅的配置。

    我从@juunas的答案中得到了线索-点2。ThxJuunas