当前位置:网站首页>[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 .
边栏推荐
- JSON format execution plan (6) - MySQL execution plan (52)
- Feixin, which lasted 15 years and had 500million users, was completely dead
- HCIP第十一天比较(BGP的配置、发布)
- Click El dropdown item/@click.native
- One stroke problem (Chinese postman problem)
- Codeforces Round #810 (Div. 2)【比赛记录】
- 一笔画问题(中国邮递员问题)
- A college archives management system based on asp.net
- Niuke brush sql---2
- Win11+VS2019配置YOLOX
猜你喜欢

Flutter multi-channel packaging operation

估值15亿美元的独角兽被爆裁员,又一赛道遇冷?

HCIP第十二天笔记整理(BGP联邦、选路规则)

AI theory knowledge map 1 Foundation

File upload and download performance test based on the locust framework

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

Probability theory and mathematical statistics
![[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve](/img/95/bec94176cadfac112585df259156c9.png)
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve

重押海外:阿里、京东、顺丰再拼“内力”

Hcip day 11 comparison (BGP configuration and release)
随机推荐
带你熟悉云网络的“电话簿”:DNS
【Oauth2】五、OAuth2LoginAuthenticationFilter
Sword finger offer (IX): abnormal jumping steps
重押海外:阿里、京东、顺丰再拼“内力”
力扣------字符串中的单词数
JSON数据传递参数&日期型参数传递
Probability theory and mathematical statistics
Some practical operations of vector
Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism
Sword finger offer (x): rectangular coverage
Thoughts on the compilation of Dr. Shuo's opening report
Leetcode 217. there are duplicate elements
JSON format execution plan (6) - MySQL execution plan (52)
我们被一个 kong 的性能 bug 折腾了一个通宵
Solve the problem that the remote host cannot connect to the MySQL database
Mysql数据目录(1)---数据库结构(二十四)
Is the account opened by flush safe?
Solution 5g technology helps build smart Parks
Learn about Pinia state getters actions plugins
The parent component accesses the methods or parameters of the child component (the child component exposes the method defineexpose)