AngularJS Azure Blob 存储的高级身份验证

AngularJS adal Authentication to Azure Blob Storage

我有一个 angularJS 项目。我在我的脚本中包含了 azure-blob-storage.js,我可以使用 SAS 访问,但不能使用 AD 身份验证。

我已将 Azure 存储 API 权限添加到 AD 应用程序注册,并将应用程序 Reader 和贡献者角色授予存储帐户。

adalAuthenticationService.acquireToken({clientId},
        function(error, token) {
          // Handle ADAL Error
          if (error || !token) {
            return;
          }
        }).then(function (token) {
var tokenCredential = new AzureStorage.Blob.TokenCredential(token);
var blobService = AzureStorage.Blob.createBlobServiceWithTokenCredential({myStorageAccountURI}, tokenCredential);

我收到以下错误:

<Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature....</Message>
<AuthenticationErrorDetail>Audience validation failed. Audience did not match.</AuthenticationErrorDetail></Error>

错误Audience validation failed. Audience did not match.表示令牌受众(=预期接收者)是错误的。您很可能会使用您的客户端 ID 为您的应用获取令牌。您需要在调用 acquireToken() 时将其切换为 https://storage.azure.com/

而且您的用户还需要 read/write 访问您发现的 blob :)