我正在使用 Azure 搜索索引器客户端。如果我使用 AdminKey 凭据,一切正常。但我想使用我的用户帐户(因为此代码将在 azure 函数中使用,并且我希望 azure 函数的系统身份直接访问搜索索引器)。 所以我尝试使用DefaultAzureCredential。但这给了我 403 错误。在天蓝色门户中,我是该实例的所有者,我还为我授予了索引读者和贡献者角色。那么有没有办法让它发挥作用呢?
var searchClient = new SearchIndexerClient(
new Uri(searchEndpoint),
new DefaultAzureCredential()
);
(await searchClient.GetIndexerStatusAsync(indexerName))
这里会抛出403异常。
在 Azure 认知搜索中为 Azure Function 的系统分配托管标识分配适当的角色。将访问控制设置为两者以启用托管身份访问。检查 Function 应用程序是否设置为使用
DefaultAzureCredential
,它将自动选取托管身份进行身份验证。