我目前正在尝试发送帖子请求至https://login.microsoftonline.com/XXX/oauth2/token用于检索应用程序的访问令牌和刷新令牌的端点。使用 axios 向端点发送 post 请求时,会发送预检,但不会返回任何响应。
错误:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
然而,对 axios post 请求使用不同的方法,它返回数据但没有预检,并给出不同的错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
两个 axios 请求:
const data = new FormData();
data.append('grant_type', this.config.grant_type);
data.append('client_id', this.config.client_id);
data.append('code', localStorage.getItem('auth_code'));
data.append('redirect_uri', this.config.redirect_uri);
data.append('client_secret', this.config.client_secret);
data.append('resource', this.config.client_id);
axios.post(`https://login.microsoftonline.com/${this.config.tenant}/oauth2/token`, data);
方法二:
axios({
method: 'post',
contentType: 'application/json',
url: `https://login.microsoftonline.com/${this.config.tenant}/oauth2/token`,
data: {
grant_type: this.config.grant_type,
client_id: this.config.client_id,
code: localStorage.getItem('auth_code'),
redirect_uri: this.config.redirect_uri,
client_secret: this.config.client_secret,
resource: this.config.client_id
}
});
这是 axios 请求本身的问题还是端点的问题?