我在angular中构建了一个应用程序,我想让经过认证的用户能够根据他们的访问权限向下引导文件为此我尝试使用Azure AD和azure rbac进行认证和认证,并使用azure blob来存储我的文件,我在互联网上搜索了很多,虽然我遇到了如何通过msal库进行认证的解决方案,但我没有找到任何关于如何认证和AUTHERIZE用户使用blob存储的解决方案,我将非常感谢许多指导或教程如何解决这个问题。致以最好的问候,女孩
发布于 2020-11-24 06:53:09
你的代码在浏览器中运行吗?目前,对于浏览器,@azure/blob-storage仅支持using SAS token
BlobServiceClient构造函数执行take a TokenCredential,这是一个您可以实现的接口:
向Azure Blob服务发送请求时,SDK库将使用提供的令牌作为持有者令牌。不过,我还没有尝试过使用RBAC。
希望在未来的SDK将有更好的集成AAD/RBAC的浏览器。
发布于 2021-06-26 23:20:09
您需要使用以下命令获取blob存储的令牌:-
this.authService
.acquireTokenSilent({
scopes: ['https://storage.azure.com/user_impersonation'],
})
.then((tokenResponse) => {tokenResponse.accessToken})然后像这样包装令牌:-
TestTokenCredential(tokenResponse.accessToken) {
return {
getToken: function (_scope, _opts) {
return {
token: tokenResponse.accessToken,
expiresOnTimestamp: Date.now() + 60 * 60 * 1000,
};
},
};
}并最终使用上述函数返回的令牌来获取blob容器客户端,如下所示:
private containerClient(token: any): ContainerClient {
return new BlobServiceClient(
`https://${this.picturesAccount}.blob.core.windows.net`,
token
).getContainerClient(this.picturesContainer);
}https://stackoverflow.com/questions/64974615
复制相似问题