【发布时间】:2018-11-28 19:33:14
【问题描述】:
我目前正在尝试向https://login.microsoftonline.com/XXX/oauth2/token 端点发送发布请求,以检索应用程序的访问令牌和刷新令牌。使用 axios 向端点发送 post 请求时,preflight 被发送,但没有返回任何响应。
错误:
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 发布请求使用不同的方法,它返回数据但没有预检并给出不同的错误:
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 请求本身的问题还是端点的问题?
【问题讨论】:
标签: javascript azure http http-headers azure-active-directory