簡體   English   中英

使用 Azure AD 和 Azure Storage PUT API 時出現無效的身份驗證信息錯誤

[英]Invalid authentication info error when using Azure AD and Azure Storage PUT API

我正在嘗試使用 Azure Active Directory (AAD) 身份驗證和 REST API 將文件上傳到 Azure 存儲中的容器。 我無法弄清楚下面的工作流程中缺少什么,但它總是失敗。

這個怎么運作:

  1. 在 AAD 中創建了服務主體 (SP)
  2. 為此 SP 生成了client_secret
  3. 在存儲帳戶級別添加到 SP 的存儲帳戶的Contributor角色
    • 附帶問題: Storage Blob Data Contributor角色是否可以縮小到容器級別,而不是在帳戶級別授予?
  4. 示例身份驗證請求:
    • 方法: GET
    • URL: https://login.microsoftonline.com/<my_tenant>/oauth2/v2.0/token
    • 正文: x-www-form-urlencoded
      • grant_type : client_credentials
      • client_id : <client_id>
      • scope : https://graph.microsoft.com/.default
      • client_secret : <client_secret>
    • 標題:
      • content-typeapplication/x-www-form-urlencoded
  5. 樣本授權。 回復:
    • 狀態:200
    • 身體:
{
    "token_type": "Bearer",
    "expires_in": 3599,
    "ext_expires_in": 3599,
    "access_token": "<auth_token>"
}
  1. 到目前為止沒有問題。 然后使用此請求中的<auth_token>發送 PUT 請求以將文件上傳到 Azure 存儲容器
  2. 示例上傳請求:
    • 方法: PUT
    • URL: https://<stg-account-name>.blob.core.windows.net/<container-name>/<file-name>.json
    • 正文: binary
      • <file-name>.json
    • 標題:
      • x-ms-blob-type : BlockBlob
      • x-ms-version2020-04-08
        • AAD 身份驗證需要(至少根據此文檔
      • AuthenticationBearer <auth_token>
  3. 示例上傳響應:
    • 狀態:401
    • 身體:
<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>InvalidAuthenticationInfo</Code>
    <Message>Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
RequestId:<guid>
Time:2022-09-26T18:29:27.4477615Z</Message>
    <AuthenticationErrorDetail>Signature validation failed. Signature verification failed.</AuthenticationErrorDetail>
</Error>

試過:

  • 從身份驗證 header 中刪除Bearer關鍵字
    • 結果狀態 403
  • x-ms-version header 從2017-11-092020-04-08
    • 沒變

問題

  1. 這里缺少什么?
  2. 這在文檔中的哪個位置?

編輯1

  1. 這里缺少什么?
    • 謝謝@gaurav-mantri,您的建議有效!
    • 我在 C 請求scope header 更改為https://storage.azure.com/.default默認值。
    • 隨后的上傳請求以狀態 201 響應。
  2. 你能幫我找到文檔中引用的這個嗎?
    • 在這些資源中找不到術語https://storage.azure.com/.default
    • 搜索詞Azure OAUTH scopes似乎在結果的第一頁中沒有顯示任何內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM