首页 > 解决方案 > AngularJS adal 对 Azure Blob 存储的身份验证

问题描述

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

我已将 Azure 存储 API 权限添加到 AD 应用注册,并将应用阅读者和参与者角色分配给存储帐户。

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>

标签: angularjsazureazure-active-directoryazure-blob-storageazureportal

解决方案


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

而且您的用户还需要拥有对 blob 的读/写访问权限,如您所见:)


推荐阅读