[英]Example of fetch() method to API with Azure AD B2C authorization
具體來說,我不知道我的標題應該是什么樣子。
使用 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.