有一个Azure Web应用程序服务,我必须在该服务上调用API获取方法。 Web应用程序服务在身份提供商保护下,呼叫者必须是Azure函数。
我收到以下消息Azure函数已经开始起作用:“您无权查看此目录或页面。” 该消息已从Azure Web应用程序发送(受Azure Identity Provider的保护)
作为你们可以意识到,Azure函数无权调用受保护的Azure Web应用程序服务。原因对我来说很明显,Web应用程序服务受Azure身份提供商的保护。
在这种情况下,如何从Azure函数中调用Web App服务上的获取方法?
There is an Azure Web App service and I have to call an API get method on that service. The web app service is under Identity Provider protection and the caller has to be an Azure function.
I have gotten the following message Azure function has started to work: "You do not have permission to view this directory or page." That message has sent from Azure Web App (protected by Azure identity provider)
As you guys can realize, the Azure function does not have permission to call the protected Azure Web App service. The reason is clear for me, the web app service is protected by Azure Identity Provider.
How can I call the get method on Web App service from the Azure function in this case?
发布评论
评论(2)
做到这一点的方法是使用托管身份,
您为Azure函数提供了一个由系统分配的身份。
然后,您可以在Azure Web应用程序上授予该系统分配的身份的权利。
请参阅:
The way to do this is to use Managed Identities
You give your Azure function a System-assigned Identity.
And then you grant rights to that System-assigned Identity on your Azure Web App.
See: https://learn.microsoft.com/en-us/azure/app-service/overview-managed-identity?tabs=portal%2Chttp
我如何理解这应该有效的是,您必须在Azure功能上启用托管身份。这将在您的Azure Active Directory内部创建一个托管应用程序(服务主体)。
然后,您将不得不授予此托管应用程序许可以调用您的Azure Web应用程序。
在您的Azure函数中,您必须使用您之前创建的托管身份为Azure Web应用程序添加一些实现。使用令牌,您可以创建一个REST请求,其中包含适用于API的访问令牌。
这是 .net的代码示例
How I understand that this should work is that you have to enable managed identity on your Azure Function. This will create a managed Application (Service Principal) inside your Azure Active Directory.
Then you will have to grant this managed application permission to invoke your Azure Web App.
In your Azure Function, you will have to add some implementation to acquire a token for your Azure Web App using the managed identity you have created earlier. With the token, you can create a REST request that contains the access token for your API.
Here is a code example for .NET