"Permissions for service are set to internal but this request was external" 对于同一资源组中的应用

"Permissions for service are set to internal but this request was external" for app in same resource group

Azure API 应用程序 documentation 简要描述了保护 API 应用程序的三种方法。其中之一是内部辅助功能设置:“内部 - 仅允许同一资源组中的其他 API 应用程序或 Web 应用程序调用 API 应用程序。”

我在同一资源组和托管计划中创建了另一个 Azure API 应用程序。但是,当我尝试从 Web 应用程序连接到内部 API 应用程序时,出现 HTTP 403 授权失败并显示以下错误消息:
“服务权限设置为内部,但此请求是外部的。”

有没有人能够在同一资源组中的 API 个应用程序之间使用内部设置?

我们很快就会对此进行记录。同时,您需要做的是以下几点。您需要安装 nuget 包 Microsoft.Azure.AppService.ApiApps.Service。然后,创建一个委托处理程序如下:

class InternalCredentialHandler : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        Runtime.FromAppSettings(request).SignHttpRequest(request);
        return base.SendAsync(request, cancellationToken);
    }
}

然后当您使用 HttpClient 或生成的客户端连接到另一个内部 API 时,只需传入委托处理程序即可。例如:

MySampleClient client = new MySampleClient(new DelegatingHandler[] { new InternalCredentialHandler() });

谢谢, 莫希特

编辑:现在可在 https://azure.microsoft.com/documentation/articles/app-service-api-dotnet-consume-internal/

获取相关文档