簡體   English   中英

帶有 Azure AD B2C 授權的 API 的 fetch() 方法示例

[英]Example of fetch() method to API with Azure AD B2C authorization

我正在尋找調用安全 API 的 fetch() 方法的示例(我使用 Azure AD B2C)

具體來說,我不知道我的標題應該是什么樣子。

使用 Postman 調用 API 並獲得授權。 我的 API 托管在 localhost:44320 我沒有部署它。

在 React 中,我使用“react-azure-adb2c”庫,它也可以工作。 我可以登錄,之后我將獲得包含我需要的所有聲明的令牌。

var token = auth.getToken(); //here is the token which is correct
fetch("https://localhost:44320/api/worker/", {
      method: "GET",
      headers: {
        Authorization: token,
        Accept: "application/json",
        Host: "localhost:44320"
      }
    })
      .then(res => res.json())
      .then(json => this.setState({ listOfWorkers: json.results }));
  }

您將 header 指定為Authorization: Bearer token-value-here

所以Authorization: 'Bearer ' + token在你的情況下。

暫無
暫無

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

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