AngularJS adal身份验证到Azure Blob存储

时间:2018-08-28 14:21:51

标签: angularjs azure azure-active-directory azure-storage-blobs azureportal

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

我已向AD App注册中添加了Azure存储API权限,并为存储帐户赋予了App 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>

1 个答案:

答案 0 :(得分:1)

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

同样,您的用户也需要对blob具有读/写访问权限:)