小编Cod*_*Avo的帖子

AADSTS9002326:仅允许“单页应用程序”进行跨域令牌兑换

我正在尝试发送跨源请求以获取我的 React spa 应用程序本地主机上的访问令牌。我收到第一个“Access-Control-Allow-Origin”错误,为了解决它,我定义了 webpack 的代理。

当我运行下面的代码块时,我收到 400 个错误请求错误。

Proxy code
'/payment': {
  target: 'https://apitest.domain.com',
  changeOrigin: true,
  secure: false,
  pathRewrite: { '^/payment': '' },
}
-------------------
  async getPaymentAccessToken() {
    const msg = await request<PaymentAccessTokenResponse>(`/payment/accesstoken/get`, {
      method: 'POST',
      prefix: undefined,
      credentials: 'include',
      headers: {
        client_id: this.client.client_id,
        client_secret: this.client.client_secret,
        'Ocp-Apim-Subscription-Key': this.client['payment-Subscription-Key'],
        'Merchant-Serial-Number': this.client['Merchant-Serial-Number']!,
      },
    });

    return msg;
  }
Run Code Online (Sandbox Code Playgroud)

{“error”:“invalid_request”,“error_description”:“AADSTS9002326:仅允许“单页应用程序”客户端类型进行跨域令牌兑换。\r\n跟踪 ID:0c7f2993-b612-434d-9cee- 244e88f51600\r\n相关 ID: 45d80262-c77f-487b-a95b-4566c736e1bc\r\n时间戳: 2022-06-07 19:14:30Z","error_codes":[9002326],"timestamp":"2022-06- 07 19:14:30Z","trace_id":"0c7f2993-b612-434d-9cee-244e88f51600","correlation_id":"45d80262-c77f-487b-a95b-4566c736e1bc","error_uri":"https://login .windows.net/error?code=9002326"}

javascript reactjs webpack axios umijs

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

axios ×1

javascript ×1

reactjs ×1

umijs ×1

webpack ×1