当前位置:网站首页>[oauth2] v. oauth2loginauthenticationfilter
[oauth2] v. oauth2loginauthenticationfilter
2022-07-26 13:29:00 【Beicheng Xiaolin】
One 、OAuth2LoginAuthenticationFilter
When gitee received OAuth2 After the authorization request , Will send a message to the browser 302 Redirect to redirect_uri Response . Because by default, the callback path satisfies /login/oauth2/code/*, The path will be OAuth2LoginAuthenticationFilter Filter interception processing .
Two 、OAuth2LoginAuthenticationFilter Structure

1、 DEFAULT_FILTER_PROCESSES_URI = “/login/oauth2/code/*”;
Default intercept path
2、 ClientRegistrationRepository
Client information
3、OAuth2AuthorizedClientRepository ;
OAuth2 Authorize client repositories
4、AuthorizationRequestRepository authorizationRequestRepository
from http Operation authorized in OAuth2 client
5、 Converter<OAuth2LoginAuthenticationToken, OAuth2AuthenticationToken> authenticationResultConverter
token converter
3、 ... and 、OAuth2 Login authentication logic
OAuth2LoginAuthenticationFilter The core of all 
In the method . It mainly implements the following logic :
- Check logic
- Verify whether it is a response to the authorization request .
- Verify whether the current authorization request really exists , Prevent forgery .
- Verify the of the current authorization request OAuth2 Whether the client is compliant .
- assemble OAuth2LoginAuthenticationToken And to OAuth2LoginAuthenticationProvider Processing authentication
- Certified OAuth2LoginAuthenticationToken adopt authenticationResultConverter Function to OAuth2AuthenticationToken
- Initialize authenticated OAuth2 Client object OAuth2AuthorizedClient And persist
- Will step ③ Generated OAuth2AuthenticationToken return


Four 、OAuth2LoginAuthenticationProvider
1、springsecurity Our certification system

2 、AuthenticationProvider
spring Supported by default in 17 Authentication method in 
3、OAuth2LoginAuthenticationToken Corresponding AuthenticationProvider
OAuth2LoginAuthenticationProvider,For ordinary OAuth2 Login authentication .OidcAuthorizationCodeAuthenticationProvider, be used for OIDC authentication .
4、OAuth2LoginAuthenticationProvider
OAuth2LoginAuthenticationProvider Responsible for using the token endpoint of the authorization server (token-uri) Authenticate the authorization code credentials , If the certification is valid , Then exchange it as access token credentials OAuth2AccessToken.
It will also use OAuth2UserService From the user information endpoint (user-info-uri) Get end users ( Resource owner ) User information for , User information to OAuth2User Create a Principal . And then OAuth2User Related to OAuth2LoginAuthenticationToken To complete authentication . The flow chart is as follows :
From the above description and flow chart, we can summarize the following two key points :
5、 ... and 、OAuth2AuthorizationCodeAuthenticationProvider
OAuth2LoginAuthenticationProvider There is also a OAuth2AuthorizationCodeAuthenticationProvider. It is responsible for using the token endpoint of the authorization server to authenticate the authorization code credentials .
- Authentication authorization code
First of all, from the OAuth2AuthorizationCodeAuthenticationToken Medium OAuth2AuthorizationExchange extract OAuth2AuthorizationResponse, Judge whether it is OAuth2 Abnormal response .
If not , And authorization request object OAuth2AuthorizationRequest Medium state Value for consistency comparison , once OAuth2 Before and after authorization request state Must be consistent .
obtain OAuth2AccessToken
And then through OAuth2AccessTokenResponseClient, The bottom one is RestTemplate, according to OAuth2 Of token-uri Just encapsulate . Wechat in the back OAuth2 We will customize this interface in Web authorization .obtain OAuth2User
Get OAuth2AccessToken Jump back OAuth2LoginAuthenticationProvider. With token Naturally, you can call the personal information interface user-info-uri 了 ,Spring Security Abstract this process as OAuth2UserService Interface :‘
Many times, the bottom layer of this interface also passes RestTemplate Realized . And in actual development OAuth2UserService The probability should be customized , Also behind wechat OAuth2 We will customize this interface in Web authorization .
Extra logic
OAuth2LoginAuthenticationProvider This is the end of the implementation , What we deal with later is AbstractAuthenticationProcessingFilter The logic of , and Form Login The logical process is consistent = What needs to be emphasized is that it has been certified OAuth2 The client object will be stored , Currently certified OAuth2AuthenticationToken Will be stored in the security context SecurityContext in .
边栏推荐
- flutter多渠道打包运行
- Comparator (interface between comparable and comparator)
- Probability theory and mathematical statistics
- Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web
- Team research and development from ants' foraging process (Reprint)
- Solve the problem that the remote host cannot connect to the MySQL database
- How to remove black edges from hyperimage images (two methods)
- MySQL data directory (2) -- table data structure (XXV)
- How to write the introduction of GIS method journals and papers?
- 解决远程主机无法连接mysql数据库的问题
猜你喜欢

如何构建以客户为中心的产品蓝图:来自首席技术官的建议

The last time I heard about eBay, or the last time

AI theory knowledge map 1 Foundation

Win11+vs2019 configuration yolox

概率论与数理统计

Emotion analysis model based on Bert

一笔画问题(中国邮递员问题)

Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism

Analysis on the current situation and optimization strategy of customer experience management in banking industry

Oom caused by improper use of multithreading
随机推荐
How to write the introduction of GIS method journals and papers?
[turn] judge the relationship between two geometries in ArcGIS
从其他文件触发pytest.main()注意事项
Activity.onStop() 延迟10秒?精彩绝伦的排查历程
多线程使用不当导致的 OOM
我们被一个 kong 的性能 bug 折腾了一个通宵
Chat system based on webrtc and websocket
Golang port scanning design
Codeforces Round #810 (Div. 2)【比赛记录】
We were tossed all night by a Kong performance bug
12 brand management of commodity system in gulimall background management
B+树索引使用(6)最左原则 --mysql从入门到精通(十八)
Student examination system based on C #
银行业客户体验管理现状与优化策略分析
Thoughts on the compilation of Dr. Shuo's opening report
Leetcode 217. there are duplicate elements
LeetCode 1523. 在区间范围内统计奇数数目
HCIP第十一天比较(BGP的配置、发布)
MVVM architecture encapsulation of kotlin series (kotlin+mvvm)
Tupu 3D visual national style design | collision between technology and culture "cool" spark“