wechat icon indicating copy to clipboard operation
wechat copied to clipboard

oauth2.AuthCodeURL生成的url会导致网页授权回调两次

Open meilihao opened this issue 6 years ago • 2 comments

llog:

2018-03-23 16:12:17	handler/weixin.go:67	/service/weixin/mp?code=071AdBVI1ZHOd509MKUI1jwjVI1AdBVV&state=385a5e02f501f8190cb5de69fe0d4d0c
2018-03-23 16:12:17	handler/weixin.go:67	/service/weixin/mp?code=001tbrPg2GWJYH07NrNg2oxqPg2tbrPQ&state=385a5e02f501f8190cb5de69fe0d4d0c

两次回调的code不同,但state相同.

解决方法 生成url时添加connect_redirect=1:

func AuthCodeURL(appId, redirectURI, scope, state string) string {
	return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + url.QueryEscape(appId) +
		"&redirect_uri=" + url.QueryEscape(redirectURI) +
		"&response_type=code&scope=" + url.QueryEscape(scope) +
		"&state=" + url.QueryEscape(state) +
		"&connect_redirect=1#wechat_redirect"
}

meilihao avatar Mar 23 '18 08:03 meilihao

请问你这个参数有文档吗???

chanxuehong avatar Mar 27 '18 06:03 chanxuehong

没有, 我是参考了网上的解决方法和通过chrome network监控 weixin整个调用过程得出的结论.

调用原有AuthCodeURL进行跳转,其实还会进行一次location, 比较了一下前后两次参数, 其实就是多了connect_redirect=1, 其他完全一样.

ps: 也网上也有人说调用原有AuthCodeURL导致网页授权回调两次是因为自身后端用了nginx的缘故,不过他们没给出解决方案.

meilihao avatar Mar 29 '18 03:03 meilihao

您的邮件已收到!谢谢!

liubin2 avatar Dec 15 '22 09:12 liubin2