Skip to content

Commit 27d63fd

Browse files
Emergent fix: Authorization consent not working
- The oauth/authorize POST is not called when there is a response_type parameter. - Remove the response_type from the oauth/authorize POST after the authorization consent. - Need to create test cases for the Authorization Code module.
1 parent 84376e4 commit 27d63fd

File tree

7 files changed

+9
-16
lines changed

7 files changed

+9
-16
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>io.github.patternhelloworld.securityhelper.oauth2.api</groupId>
2626
<artifactId>spring-oauth2-easyplus</artifactId>
27-
<version>4.4.0</version>
27+
<version>4.4.1</version>
2828
</dependency>
2929
```
3030

@@ -246,7 +246,7 @@ public class CommonDataSourceConfiguration {
246246
2. Check the login page at the "resources/templates/login.hml"
247247
3. Ensure the callback URL (http://localhost:8081/callback1) is properly set in the ``oauth2_registered_client`` table in the database.
248248
- How to use
249-
1. Open the web browser by connecting to ``http://localhost:8370/oauth2/authorize?response_type=code&client_id=client_customer&state=xxx&scope=read&redirect_uri=http%3A%2F%2Flocalhost%3A8081%2Fcallback1&code_challenge=HVoKJYs8JruAxs7hKcG4oLpJXCP-z1jJQtXpQte6GyA&code_challenge_method=S256``, using the values from the ``oauth2_registered_client``
249+
1. Open the web browser by connecting to ``http://localhost:8370/oauth2/authorize?client_id=client_customer&state=xxx&scope=read&redirect_uri=http%3A%2F%2Flocalhost%3A8081%2Fcallback1&code_challenge=HVoKJYs8JruAxs7hKcG4oLpJXCP-z1jJQtXpQte6GyA&code_challenge_method=S256``, using the values from the ``oauth2_registered_client``
250250
- PKCE (``code_challege, code_challege_METHOD``) is optional.
251251
- PKCE adds a Code Verifier and a Code Challenge to the flow, enhancing the Authorization Code Grant Flow by preventing the issuance of an Access Token if the Authorization Code is compromised.
252252
2. Login with ``[email protected] / 1234 ``

client/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
77
<modelVersion>4.0.0</modelVersion>
88
<groupId>com.patternhelloworld.securityhelper.oauth2.client</groupId>
99
<artifactId>spring-oauth2-easyplus-client</artifactId>
10-
<version>4.4.0</version>
10+
<version>4.4.1</version>
1111
<packaging>jar</packaging>
1212

1313
<properties>
@@ -48,7 +48,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
4848
<dependency>
4949
<groupId>io.github.patternhelloworld.securityhelper.oauth2.api</groupId>
5050
<artifactId>spring-oauth2-easyplus</artifactId>
51-
<version>4.4.0</version>
51+
<version>4.4.1</version>
5252
</dependency>
5353

5454
<!-- DB -->

client/src/main/java/com/patternhelloworld/securityhelper/oauth2/client/config/securityimpl/response/CustomWebAuthenticationFailureHandlerImpl.java

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
5757
}
5858
Map<String, String> consentAttributes = new HashMap<>();
5959
consentAttributes.put("clientId", request.getParameter("client_id"));
60+
//consentAttributes.put("responseType", request.getParameter("response_type"));
6061
consentAttributes.put("redirectUri", request.getParameter("redirect_uri"));
6162
consentAttributes.put("code", request.getParameter("code"));
6263
consentAttributes.put("state", request.getParameter("state"));

client/src/main/resources/templates/consent.html

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ <h1 class="text-center text-primary">App permissions</h1>
4747
<div class="col text-center">
4848
<form name="consent_form" method="post" action="/oauth2/authorize">
4949
<input type="hidden" name="client_id" th:value="${consentAttributes.clientId}">
50+
<!--<input type="hidden" name="response_type" th:value="${consentAttributes.responseType}">-->
5051
<input type="hidden" name="redirect_uri" th:value="${consentAttributes.redirectUri}">
5152
<input type="hidden" name="code" th:value="${consentAttributes.code}">
5253
<input type="hidden" name="state" th:value="${consentAttributes.state}">

client/src/main/resources/templates/login.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h1 class="h3 mb-3 fw-normal">Please sign in</h1>
7373
const password = passwordInput.value;
7474

7575
// Extract query parameters from the current URL
76-
const {client_id, response_type, state, scope, redirect_uri, code_challenge, code_challenge_method} = getQueryParameters();
76+
const {client_id, state, scope, redirect_uri, code_challenge, code_challenge_method} = getQueryParameters();
7777

7878
// Basic Auth header creation
7979
const clientSecret = '12345'; // Enter client secret
@@ -83,7 +83,7 @@ <h1 class="h3 mb-3 fw-normal">Please sign in</h1>
8383
'username': username,
8484
'password': password,
8585
'grant_type': "password",
86-
'response_type': response_type,
86+
'response_type': "code",
8787
'scope': scope
8888
};
8989

lib/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
88

99
<groupId>io.github.patternhelloworld.securityhelper.oauth2.api</groupId>
1010
<artifactId>spring-oauth2-easyplus</artifactId>
11-
<version>4.4.0</version>
11+
<version>4.4.1</version>
1212
<name>spring-oauth2-easyplus</name>
1313
<description>App-Token based easy OAuth2 JPA implementation built to grow with Spring Boot</description>
1414
<packaging>jar</packaging>

lib/src/main/java/io/github/patternhelloworld/securityhelper/oauth2/api/config/security/validator/endpoint/authorization/CodeRequestValidator.java

-9
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ public CodeValidationResult apply(MultiValueMap<String, String> queryParameters)
3434

3535
String clientId = validateClientIdForCodeRequest(queryParameters);
3636

37-
String responseType = queryParameters.getFirst(OAuth2ParameterNames.RESPONSE_TYPE);
38-
if (!StringUtils.hasText(responseType)) {
39-
throw new EasyPlusOauth2AuthenticationException(EasyPlusErrorMessages.builder().errorCode(EasyPlusErrorCodeConstants.MISSING_RESPONSE_TYPE).message(EasyPlusErrorCodeConstants.MISSING_RESPONSE_TYPE).userMessage(iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHENTICATION_LOGIN_ERROR)).build());
40-
}else{
41-
if(!responseType.equals("code")){
42-
throw new EasyPlusOauth2AuthenticationException(EasyPlusErrorMessages.builder().errorCode(EasyPlusErrorCodeConstants.WRONG_RESPONSE_TYPE).message(EasyPlusErrorCodeConstants.WRONG_RESPONSE_TYPE).userMessage(iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHENTICATION_LOGIN_ERROR)).build());
43-
}
44-
}
4537
String redirectUri = queryParameters.getFirst(OAuth2ParameterNames.REDIRECT_URI);
4638
if (!StringUtils.hasText(redirectUri)) {
4739
throw new EasyPlusOauth2AuthenticationException(EasyPlusErrorMessages.builder().errorCode(EasyPlusErrorCodeConstants.MISSING_REDIRECT_URI).message(EasyPlusErrorCodeConstants.MISSING_REDIRECT_URI).userMessage(iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHENTICATION_LOGIN_ERROR)).build());
@@ -65,7 +57,6 @@ public CodeValidationResult apply(MultiValueMap<String, String> queryParameters)
6557

6658
return CodeValidationResult.builder()
6759
.clientId(clientId)
68-
.responseType(responseType)
6960
.redirectUri(redirectUri)
7061
.state(state)
7162
.scope(registeredScopes)

0 commit comments

Comments
 (0)