微信公众号OAuth2用户授权报错跨域,Origin 'null' is therefore not allowed access

时间:2019-03-01 15:43:01   收藏:0   阅读:2442

重定向到微信授权页面时调试发现Status Code:301 Moved Permanently并且报错提示跨域:

XMLHttpRequest cannot load
https://open.weixin.qq.com/connect/oauth2/authorize...#wechat_redirect. Redirect
from 'https://open.weixin.qq.com/connect/oauth2/authorize...#wechat_redirect' to
'https://open.weixin.qq.com/connect/oauth2/authorize...#wechat_redirect' has been
blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the
requested resource. Origin 'null' is therefore not allowed access.

在调试界面发现Headers里面出现了两次重定向,所以才导致了这个问题。

解决方法是在微信提供的授权页面链接中添加connect_redirect=1

https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIR
ECT_URI&response_type=code&scope=SCOPE&state=STATE&connect_redirect=1#wechat_redirect

再请求时Status Code:200 OK

原文地址:https://www.jianshu.com/p/8feea4d8e1c0

原文:https://www.cnblogs.com/huayueniansi/p/10456344.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!