|
39 | 39 | import org.springframework.security.oauth2.core.OAuth2Error; |
40 | 40 | import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse; |
41 | 41 | import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; |
| 42 | +import org.springframework.security.oauth2.core.endpoint.PkceParameterNames; |
42 | 43 | import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationException; |
43 | 44 | import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationProvider; |
44 | 45 | import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken; |
@@ -150,18 +151,24 @@ private static RequestMatcher createDefaultRequestMatcher(String authorizationEn |
150 | 151 | HttpMethod.GET.name()); |
151 | 152 | RequestMatcher authorizationRequestPostMatcher = new AntPathRequestMatcher(authorizationEndpointUri, |
152 | 153 | HttpMethod.POST.name()); |
153 | | - |
154 | | - RequestMatcher responseTypeParameterMatcher = ( |
155 | | - request) -> request.getParameter(OAuth2ParameterNames.RESPONSE_TYPE) != null; |
156 | | - |
| 154 | + RequestMatcher authorizationConsentMatcher = createAuthorizationConsentMatcher(authorizationEndpointUri); |
157 | 155 | RequestMatcher authorizationRequestMatcher = new OrRequestMatcher(authorizationRequestGetMatcher, |
158 | | - new AndRequestMatcher(authorizationRequestPostMatcher, responseTypeParameterMatcher)); |
159 | | - RequestMatcher authorizationConsentMatcher = new AndRequestMatcher(authorizationRequestPostMatcher, |
160 | | - new NegatedRequestMatcher(responseTypeParameterMatcher)); |
161 | | - |
| 156 | + new AndRequestMatcher(authorizationRequestPostMatcher, |
| 157 | + new NegatedRequestMatcher(authorizationConsentMatcher))); |
162 | 158 | return new OrRequestMatcher(authorizationRequestMatcher, authorizationConsentMatcher); |
163 | 159 | } |
164 | 160 |
|
| 161 | + private static RequestMatcher createAuthorizationConsentMatcher(String authorizationEndpointUri) { |
| 162 | + final RequestMatcher authorizationConsentPostMatcher = new AntPathRequestMatcher(authorizationEndpointUri, |
| 163 | + HttpMethod.POST.name()); |
| 164 | + return (request) -> authorizationConsentPostMatcher.matches(request) |
| 165 | + && request.getParameter(OAuth2ParameterNames.RESPONSE_TYPE) == null |
| 166 | + && request.getParameter(OAuth2ParameterNames.REQUEST_URI) == null |
| 167 | + && request.getParameter(OAuth2ParameterNames.REDIRECT_URI) == null |
| 168 | + && request.getParameter(PkceParameterNames.CODE_CHALLENGE) == null |
| 169 | + && request.getParameter(PkceParameterNames.CODE_CHALLENGE_METHOD) == null; |
| 170 | + } |
| 171 | + |
165 | 172 | @Override |
166 | 173 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
167 | 174 | throws ServletException, IOException { |
|
0 commit comments