azure-functions - 将某些 Azure Functions 的访问权限限制为 AD 组的成员
问题描述
在我的客户域中新尝试使用 Azure Functions,我已经成功部署了一个,并从 .NET 控制台应用程序调用它。
我想限制作为 AD 组成员的内部用户访问该功能。我意识到这可能不是函数的用途,所以不要犹豫,表达你的保留意见。
尽管花了几个小时在谷歌上搜索,我所能实现的只是激活 AppService 身份验证,如“配置身份验证和授权”部分所述。
然后我的控制台应用程序开始失败,代码 401 Unauthorized 和响应内容中的“您无权查看此目录或页面” - 到目前为止一切顺利......然后我想我可以告诉 Azure 要求成为 AD 成员组来调用函数,à la WCF,但是如何?我无法管理我客户的 Azure Active Directory,所以也许我无法到达可以建立这种关联的位置(如果可能的话)。
这是我调用该函数的代码:
private static async void CallMyTypedFunctionAsync()
{
var functionAddress = "https://[...].azurewebsites.net/api/MyTypedFunction";
var requestDto = new DataContracts.MyTypedFunctionReqest { X = 6, Y = 7 };
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, functionAddress)
{
Content = new StringContent(JsonConvert.SerializeObject(requestDto), Encoding.UTF8, "application/json")
};
var httpClient = new HttpClient();
var response = await httpClient.SendAsync(message);
var responseContent = await response.Content.ReadAsStringAsync();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var responseDto = JsonConvert.DeserializeObject<DataContracts.MyTypedFunctionResponse>(responseContent);
Console.WriteLine("CallMyTypedFunctionAsync's result: {0}", responseDto.Z); // 42
}
else
Console.WriteLine("CallMyTypedFunctionAsync has failed. {0}: {1}", response.StatusCode, responseContent);
}
解决方案
正如 Thomas 提到的,您需要将 AD 同步到 Azure AD 目录。如何做到这一点,您可以参考将您的本地目录与 Azure Active Directory 集成。
有关如何访问受 Azure AD 保护的 Azure Function,请参阅 Azure Functions 和应用服务身份验证中功能部分的使用身份验证
推荐阅读
- php - PHP如果计数,第一篇文章不进入行
- c# - Linq 实体框架
- python - Jupyter - 从另一个分区打开文件
- swift - 为什么 Swift 库使用“enum CommandLine”而不是“struct CommandLine”?
- javascript - 将矩范围导入 Angular 4.x 应用程序(ES6) - 没有兼容的调用签名错误?
- html - 我已经尝试让这个@media 代码工作 30 分钟,但我仍然找不到答案
- junit - Junit:org.mockito.exceptions.misusing.MissingMethodInvocationException:
- hive - 为什么单个计数与蜂巢中的总体计数不同
- iis - Laravel 尝试从旧文件夹加载文件
- python-3.x - 无法在 sqlite 数据库中插入唯一值