具有Azure AD B2C授权的API的fetch()方法示例

问题描述 投票:0回答:1

我正在寻找调用安全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 }));
  }
javascript reactjs azure azure-active-directory fetch-api
1个回答
0
投票

您将标题指定为Authorization: Bearer token-value-here

© www.soinside.com 2019 - 2024. All rights reserved.