Skip to content

Commit

Permalink
Merge pull request #2658 from kayathiri4/add-wrapper
Browse files Browse the repository at this point in the history
Add wrapper for device code grant request
  • Loading branch information
kayathiri4 authored Jan 6, 2025
2 parents 9095d8d + c5d5091 commit 71fa07f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.wso2.carbon.identity.oauth.common.OAuth2ErrorCodes;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
import org.wso2.carbon.identity.oauth.endpoint.OAuthRequestWrapper;
import org.wso2.carbon.identity.oauth.endpoint.exception.TokenEndpointBadRequestException;
import org.wso2.carbon.identity.oauth.endpoint.util.EndpointUtil;
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
Expand Down Expand Up @@ -81,6 +82,9 @@ public Response authorize(@Context HttpServletRequest request, MultivaluedMap<St
return handleErrorResponse(oAuthClientAuthnContext);
}

// Wrap the request to avoid missing of request attributes.
request = new OAuthRequestWrapper(request, paramMap);

try {
validateRepeatedParams(request, paramMap);
String deviceCode = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.lang.reflect.Method;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -225,6 +226,19 @@ public void testDevice(String clientId, int expectedStatus, boolean status)
DeviceFlowPersistenceFactory::getInstance).thenReturn(this.deviceFlowPersistenceFactory);
lenient().when(this.deviceFlowPersistenceFactory.getDeviceFlowDAO()).thenReturn(deviceFlowDAO);
lenient().when(deviceFlowDAO.checkClientIdExist(anyString())).thenReturn(status);

lenient().when(httpServletRequest.getParameterNames()).thenReturn(new Enumeration<String>() {
@Override
public boolean hasMoreElements() {
return false; // Return false to simulate no parameter names
}

@Override
public String nextElement() {
return null; // Return null as there's no next element
}
});

response = deviceEndpoint.authorize(httpServletRequest, new MultivaluedHashMap<>(),
httpServletResponse);
Assert.assertEquals(expectedStatus, response.getStatus());
Expand Down

0 comments on commit 71fa07f

Please sign in to comment.