[英]**No 'Access-Control-Allow-Origin' header is present on the requested resource.**
[英]No 'Access-Control-Allow-Origin' header is present on the requested resource. - React/Node API
我正在尝试使用Twitter进行护照认证。 我的设置如下:React(带有redux)前端(create-react-app),Node(带有express)API。 两者都在localhost(不同的端口)上运行。
用户转到/login
并单击调度登录操作的按钮:
export function login() {
return dispatch => {
return axios.get('/api/auth/twitter')
.then(() => {})
}
}
服务器上的路由:
router.get('/twitter', passport.authenticate('twitter'));
以及回调的路线:
router.get('/twitter/callback', passport.authenticate('twitter', {failureRedirect: '/login'}), loginSuccess);
loginSuccess
目前不执行任何操作。
这是我得到的完整错误:
XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=fGVctgAAAAAA1y22AAABXah3t3o. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:3000' is therefore not allowed access.
我正在将请求从React前端(localhost:3000)代理到localhost:8080。
如果我进入chrome devtools的网络标签,然后从twitter api中选择响应,则如下所示:
如果有人知道如何通过护照设置者身份验证来使用这种设置,请告诉我。
不幸的消息是,Twitter不允许您调用其API客户端,您需要一台服务器才能做到这一点:(
看看这个Quora的答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.