Microsoft Powerbi React访问令牌错误no no' Access-Control-Allow-Origin'标题存在于请求的资源上
我正在尝试在我的React应用程序中获取Microsoft PowerBi访问令牌,并且显示错误时,当我使用fetch时,请求的资源上没有“访问控制”标头。您可以找到我在下面尝试的内容: -
useEffect(() => {
let accessTokenData = {
'grant_type':'password',
'username':'******',
'password':'******',
'client_id': '**********',
'client_secret': '********',
'resource': 'https://analysis.windows.net/powerbi/api'
}
let formbody = [];
for (let property in accessTokenData) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(accessTokenData[property]);
formbody.push(encodedKey + "=" + encodedValue);
}
formbody = formbody.join("&");
fetch(`https://login.microsoftonline.com/common/oauth2/token`, {
// mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: formbody
})
.then( data => data.json())
.then(
data => {
setAccessToken(data)
console.log(data['access_token'])
}
)
.catch( error => console.error(error))
}, []);
如果您经历了处理此问题的经历或从事类似的事情,我要求您指导我这一问题。
I am trying to get microsoft powerbi access token in my react app and it is showing error No 'Access-Control-Allow-Origin' header is present on the requested resource when I use fetch. You can find what I tried below :-
useEffect(() => {
let accessTokenData = {
'grant_type':'password',
'username':'******',
'password':'******',
'client_id': '**********',
'client_secret': '********',
'resource': 'https://analysis.windows.net/powerbi/api'
}
let formbody = [];
for (let property in accessTokenData) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(accessTokenData[property]);
formbody.push(encodedKey + "=" + encodedValue);
}
formbody = formbody.join("&");
fetch(`https://login.microsoftonline.com/common/oauth2/token`, {
// mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: formbody
})
.then( data => data.json())
.then(
data => {
setAccessToken(data)
console.log(data['access_token'])
}
)
.catch( error => console.error(error))
}, []);
On loading the page it is showing the following error
If you have experienced dealing with this issue or worked on something similar I request you to please guide me in this regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误是由于CORS造成的,请在thread -github.com/jaredhanson/passport/issues/582上检查类似问题
This error is due to cors, check the similar issue on thread - github.com/jaredhanson/passport/issues/582