关于OAuth 2.0:如何在活动目录中添加权限? (有关在天蓝色中设置多租户应用程序的问题)

how to add permissions across active directory? (problems with setting up multi-tenant app in azure)

现在我在Azure活动目录1中有一个应用程序,在Azure活动目录2中有一个Web api。我的目的是允许AAD1和AAD2中的用户都可以登录该应用程序。

到目前为止,我已经将App和Api启用为多租户,并在清单中彼此添加为已知的客户端应用程序。

我还没有完成的事情:将一个作为自定义域添加到另一个中,添加权限btw api和app,而我在这两个上遇到了一些问题。

现在我的错误消息是:

An error has occurred while authorizing access via Authorization Server: unauthorized_client AADSTS65005: Invalid > resource. The client has requested access to a resource which is not listed in the requested permissions in the client's application registration.

当我尝试在api中的所需权限列表中提供访问权限时,我没有看到该Web应用程序(位于另一个目录中)。我该怎么办?

如果我将App和Api都移到同一目录下,是否存在允许其他目录中的用户登录的信息?


除了Shawn Tabrizi的回答外,您还可以将API指定为该应用程序的已知客户端应用程序。

因此在您应用的清单中:

1
2
3
"knownClientApplications": [
 "your-api-client-id"
]

然后,如果您尝试对应用进行身份验证,它也可以同时同意该API。


为了使您可以在租户1中看到Web API作为" Required Permission List "的选项,您需要将Web API的服务主体设置到Tenant 1中。

您可以通过多种方法来执行此操作,但是最简单的方法可能是通过生成登录URL来简单地登录Web API。使用租户1中的用户登录后,将在租户中预配服务主体,然后将其作为可供选择的选项。

1
https://login.microsoftonline.com/common/oauth2/authorize?client_id=&response_type=code&redirect_uri=<replyurl>&resource=<resource>&prompt=consent

另一个选择可能是使用AAD PowerShell根据您的Web API应用ID创建服务主体:

New-a?Azurea?ADa?Servicea€?Principal

1
New-AzureADServicePrincipal -AccountEnabled $true -AppId $MyApp.AppId -DisplayName $App -Tags {WindowsAzureActiveDirectoryIntegratedApp}

一旦成功将服务主体设置为所需的权限,上述错误消息就会消失。