【发布时间】:2021-12-13 22:48:46
【问题描述】:
我想使用 Azure Active Directory 允许用户从单页 Web 应用读取和写入 Azure 存储(特别是所有 Blob 和表)。
我是这样开始的:
import { InteractiveBrowserCredential } from '@azure/identity';
import { TableClient, TableServiceClient } from '@azure/data-tables';
const credentials = new InteractiveBrowserCredential({
clientId: myAuthConfig.clientId,
tenantId: myAuthConfig.tenantId,
});
const client = new TableServiceClient(
`https://${myAuthConfig.storageAccountName}.table.core.windows.net`,
credentials
);
client.listTables().byPage().next().then(console.log);
这完全没问题!我可以看到帐户上的所有表格。但后来我想列出表中的一些数据in。所以我做了:
const client = new TableClient(
`https://${myAuthConfig.storageAccountName}.table.core.windows.net`,
'<table name>',
credentials
);
client.listEntities().byPage().next().then(console.log);
但这会报错:
{
"odata.error": {
"code":"AuthorizationPermissionMismatch",
"message": {
"lang":"en-US",
"value":"This request is not authorized to perform this operation using this permission.\nRequestId:<uuid>\nTime:2021-10-28T18:04:00.0737419Z"
}
}
}
我对这个错误感到非常困惑。据我所知,我做的一切都是对的。我遵循了每个教程。我为我的应用设置了 Active Directory 权限以使用存储 API,我的 Microsoft 帐户有权访问表,启用了 OCRS,等等。
我不知道为什么我可以看到一张桌子,但看不到里面有什么。我尝试使用InteractiveBrowserCredential.authenticate 来明确设置这样的范围:
const scopes = ["User.Read"]
credentials.authenticate(scopes).then(console.log);
它适用于User.Read,但我无法弄清楚哪些范围对应于存储读/写访问。如果我添加了一个像 "Microsoft.Storage" 这样的 scopy,它会告诉我它不存在
以前有没有人遇到过这样的错误?我应该在这里做什么?
【问题讨论】:
-
您是否已将
Storage Table Data Roles分配给用户?您需要查看的角色是Storage Table Data Contributor 或Storage Table Data Reader。
标签: javascript azure azure-active-directory azure-storage azure-table-storage