无法加载 https://login.microsoftonline.com/common/oauth2/v2.0/token

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

从这个 url 获得代码后,我正在尝试使用 Outlook REST API 获取令牌

https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize

我对 axios 使用了

POST
请求,但问题是我收到了这个错误:

对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问来源'http://localhost:3000'。

我的 Axios 帖子是这样的:

return Axios({
    method: 'post',
    url: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Access-Control-Allow-Origin':'*', Content-Type, origin, authorization, accept, client-security-token"
    },
    data: {
        'client_id': 'xxxxxx',
        'scope': 'calendars.readwrite',
        'code': encodeURIComponent('000000000'),
        'redirect_uri': encodeURIComponent('http://localhost:3000/storeprofile/xxxxxxxxx/outlook-scheduler'),
        'grant_type': 'authorization_code',
        'client_secret': encodeURIComponent('xxxxxxxxxx')
    };,
    responseType: 'json'
    }).then((response) => {
        console.log('token response: ', response);
    });

我获得了

200
状态,但看不到我应该在响应中获得的令牌。响应应该是
json
,但仍然没有。

有人可以指导我吗?提前谢谢你!

reactjs azure-active-directory axios outlook-restapi
1个回答
0
投票

注册应用程序时,必须设置

Redirect URI/URL
,通常此网址将添加到CORS 标头。

文档:https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview#how-do-i-get-my-app-talking-to-azure-ad-and-microsoft-图

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