table of Contents
Registration processing logic, turned / signup Routing Problem
QQ landing
Articles connected, an error at the time of the jump
The main reason is the callback address error.
The default callback address
After actually registered to our callback address
First modify the local access address
Address modification access
Prior to the analysis, we also know that the default is / auth / qq, so we need our own Write Filter
Inside knowledge of the above configuration, the external configuration have to configure
Start landing
View Log
Why will jump to / sigin it? We analyze its processes
OAuth2AuthenticationService determines whether the class of non-null code logic: first, when the user clicks the authorization code when hoplinks /qqLogin/callback.do, when verified after scanning, or jump back when /qqLogin/callback.do, the first jump was not carrying code, will be executed if the statement is verified carries the second code, the content will be executed if else inside
Lay breakpoints, restart
Transmitting the authorization request a post
Acquired by the request receiving post json format, but is returned back to text / html
Then an exception will be reported
Return null
token will return a null
Failure to processor inside
Then it will enter into its failure processor inside
And then redirected to the / signin, but because we do not so we being given its authorization
In it did not deal with requests for information text / html, so we have to write your own RestTemplate
Creating QQOAuth2Template, rewrite method createRestTemplate
But we can not see the json format qq return, we'll have to be processed
So we need to override postForAccessGrant
Remember to set to true, because qq authorization is required five parameters
Modify the template to write their own
Restart the scan is complete
After successful jumps to / signup
Entered into SocialAuthenticationProvider
Try to acquire user information database userid, because it is the first landing, there is no database data, so the return is null
会报错异常
处理注册逻辑,调转/signup路径问题
上面问题可知,social将我们导向了一个signup的注册路径
接着上面就会抛出异常BadCredentialsException
异常会被SocialAuthenticationFilter处理
跳转到注册的url上,也就是/signup路径上
创建注册页
配置注册页属性
上面的配置是属于框架内部的配置,下面的类似于前后端分离的外部配置,覆盖内部配置
添加授权
将注册路径放入到过滤器中
重新启动,就会写到数据库里面
第二次登陆就会进入到主页
上面那个是需要进入到注册页面,但是一般情况下是后台直接帮你注册,相当于第三方登陆之后直接进入到主页
我们之前分析了,主要是第一次的时候到数据库里面查没有查到所以就会跳转到注册页面
我们可以看到它在执行查询
从代码中我们可以看到,重点connectionSignUp实现时候返回newUserId,所以我们需要手动去添加
启动