在没有 SAS 密钥的情况下从浏览器将文件上传到 Azure Blob 存储
Upload file to Azure Blob Storage from browser without SAS key
我知道可以上传到 Azure Blob 存储 using SAS keys。
这在 React 中工作得很好
import { BlobServiceClient } from "@azure/storage-blob";
const account = env.REACT_APP_BLOB_ACCOUNT_NAME;
const sas = env.REACT_APP_BLOB_SAS;
const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net${sas}`
const containerClient = blobServiceClient.getContainerClient(container);
const blockBlobClient = containerClient.getBlockBlobClient(destination);
blockBlobClient.upload(data, data.size)
据我了解,如果允许任何用户在登录后上传内容,使用 SAS 密钥可能会造成安全漏洞。SAS 不能依赖于用户,如果 SAS 密钥被嗅探,它可以在应用程序中打开安全漏洞。
在亚马逊,可以通过Cognito验证用户身份和权限,然后直接上传到S3。如何使用 Azure Blob 存储和 Azure AD 实现这一目标?
您可以参考 this documentation to setup AAD for your application and then have a look at THIS documentation which shows how to setup your BlobServiceClient with these credentials. HERE 是来自 Github 的示例。
另一种方法是使用其余 API。
您可以先在 Azure 活动目录上进行身份验证 LINK to get a token. Pass this as bearer token in the Putblob 休息 api 调用。
我知道可以上传到 Azure Blob 存储 using SAS keys。
这在 React 中工作得很好
import { BlobServiceClient } from "@azure/storage-blob";
const account = env.REACT_APP_BLOB_ACCOUNT_NAME;
const sas = env.REACT_APP_BLOB_SAS;
const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net${sas}`
const containerClient = blobServiceClient.getContainerClient(container);
const blockBlobClient = containerClient.getBlockBlobClient(destination);
blockBlobClient.upload(data, data.size)
据我了解,如果允许任何用户在登录后上传内容,使用 SAS 密钥可能会造成安全漏洞。SAS 不能依赖于用户,如果 SAS 密钥被嗅探,它可以在应用程序中打开安全漏洞。
在亚马逊,可以通过Cognito验证用户身份和权限,然后直接上传到S3。如何使用 Azure Blob 存储和 Azure AD 实现这一目标?
您可以参考 this documentation to setup AAD for your application and then have a look at THIS documentation which shows how to setup your BlobServiceClient with these credentials. HERE 是来自 Github 的示例。
另一种方法是使用其余 API。 您可以先在 Azure 活动目录上进行身份验证 LINK to get a token. Pass this as bearer token in the Putblob 休息 api 调用。