【问题标题】:"Authentication not in correct format" when setting Azure Blob Service Properties (REST API)设置 Azure Blob 服务属性 (REST API) 时出现“身份验证格式不正确”
【发布时间】:2014-03-27 18:30:54
【问题描述】:

我正在尝试通过关注these instructions 在我的 Azure Blob 存储帐户上设置 CORS 规则。

这是我提出请求后收到的错误:

400 身份验证信息的格式不正确。检查 Authorization 标头的值

请求网址:

PUT https://[MyAccountName].blob.core.windows.net/?restype=service&comp=properties

请求头:

x-ms-version: 2013-08-15
x-ms-date: Tue, 25 Feb 2014 13:02:00 GMT
Authorization: SharedKey
[MyAccountName]: [MyAccountKey]
Content-Length: 329
Host: [MyAccountName].blob.core.windows.net

请求正文:

<?xml version="1.0" encoding="utf-8"?>
<StorageServiceProperties>
    <Cors>   
          <CorsRule>
                <AllowedOrigins>http://www.example.com</AllowedOrigins>
                <AllowedMethods>GET</AllowedMethods>
                <ExposedHeaders>x-ms-meta-data*,x-ms-meta*</ExposedHeaders>
                <AllowedHeaders>x-ms-meta-target*,x-ms-meta*</AllowedHeaders>
                <MaxAgeInSeconds>200</MaxAgeInSeconds>
        </CorsRule>
    <Cors>
</StorageServiceProperties>

【问题讨论】:

    标签: azure-storage


    【解决方案1】:

    对于访问此页面并想知道为什么即使您使用共享访问签名 URL 仍会收到此错误的人,那么您很可能正在将您的 APP 令牌发送到 Azure。在这种情况下,请确保不包含 Authorization 标头。

    【讨论】:

    • 是的。我正在从其他东西添加基本的身份验证标头并遇到了这个。
    【解决方案2】:

    按照@jsgoupil 所说的:

    对于访问此页面并想知道为什么即使您使用共享访问签名 URL 仍会收到此错误的人,那么您很可能正在将您的 APP 令牌发送到 Azure。在这种情况下,请确保不包含 Authorization 标头。

    如果您有拦截器,则可以按照此 stackOverflow 帖子中的说明向请求添加跳转: https://stackoverflow.com/a/49047764/5232022

    export const InterceptorSkipHeader = 'X-Skip-Interceptor'; // <-- ADD THIS
    
    @Injectable()
    export class SkippableInterceptor implements HttpInterceptor {
    
      intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        // Add the following if to your interceptor
        if (req.headers.has(InterceptorSkipHeader)) {
          const headers = req.headers.delete(InterceptorSkipHeader);
          return next.handle(req.clone({ headers }));
        }
    
        ...  // intercept
      }
    
    }
    

    然后,每当您想跳过对特定请求的拦截时:

    const headers = new HttpHeaders().set(InterceptorSkipHeader, ''); // <-- this will skip it
    
    this.httpClient.get<ResponseType>(someUrl, { headers }) // <-- dont forget to add it here as well
    

    【讨论】:

    • 谢谢 - 我每隔几周就会遇到这个问题,但总是忘记问题是什么。 :)
    【解决方案3】:

    请求的授权标头不完整。它需要包含身份验证方案、存储帐户名称和签名。例如;

    Authorization: SharedKey myaccount:Z1lTLDwtq5o1UYQluucdsXk6/iB7YxEu0m6VofAEkUE=
    

    有关详细信息,请参阅Authentication for the Windows Azure Storage Services。另一方面,如果您使用其中一个 Windows Azure 存储客户端库,它将为您处理身份验证。对于 .NET 库,请参阅我们的NuGet package

    【讨论】:

      【解决方案4】:

      我尝试使用 Azure blob 存储 .NET SDK v12 使用共享访问签名 URL 从存储中删除文件。

      收到上述错误是因为我在使用 SAS URL 创建 blobClient 时最初包含了 StorageSharedKeyCredential

      只需删除存储凭据即可解决问题:

          public async Task DeleteFileFromStorage(string Uri)
          {
              Uri blobUri = GetDeletableSasUriForBlob(Uri);
              /*StorageSharedKeyCredential storageCredentials =
                  new StorageSharedKeyCredential(_options.Value.AccountName, _options.Value.AccountKey);*/
              // Create the blob client.
              BlobClient blobClient = new BlobClient(blobUri);      //, storageCredentials);
              //Delete the file
              await blobClient.DeleteIfExistsAsync(DeleteSnapshotsOption.IncludeSnapshots);
          }
      

      【讨论】:

        猜你喜欢
        • 2012-06-21
        • 1970-01-01
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        • 2014-01-10
        • 2019-02-25
        • 1970-01-01
        • 2017-03-05
        相关资源
        最近更新 更多