Skip to content

Commit 3aa929c

Browse files
authored
Merge pull request #156 from dhaura/DP-fix-native-sdk-based-auth-flow
Improve "canHandle" Method to Support Native SDK based Federation
2 parents 2e8ff52 + 288bf6a commit 3aa929c

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

components/org.wso2.carbon.identity.application.authenticator.oidc/src/main/java/org/wso2/carbon/identity/application/authenticator/oidc/OpenIDConnectAuthenticator.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,8 @@
115115
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.LogConstants.ActionIDs.PROCESS_AUTHENTICATION_RESPONSE;
116116
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.LogConstants.OUTBOUND_AUTH_OIDC_SERVICE;
117117
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.OIDC_FEDERATION_NONCE;
118-
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.PROMPT_TYPE;
119118
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.REDIRECTION_PROMPT;
120-
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.REDIRECT_URL;
121119
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.REDIRECT_URL_SUFFIX;
122-
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.REQUIRED_PARAMS;
123120
import static org.wso2.carbon.identity.base.IdentityConstants.FEDERATED_IDP_SESSION_ID;
124121

125122
/**
@@ -197,7 +194,13 @@ public boolean canHandle(HttpServletRequest request) {
197194
if (LOG.isTraceEnabled()) {
198195
LOG.trace("Inside OpenIDConnectAuthenticator.canHandle()");
199196
}
200-
boolean canHandle = OIDCAuthenticatorConstants.LOGIN_TYPE.equals(getLoginType(request));
197+
198+
boolean canHandle;
199+
if (isNativeSDKBasedFederationCall(request)) {
200+
canHandle = true;
201+
} else {
202+
canHandle = OIDCAuthenticatorConstants.LOGIN_TYPE.equals(getLoginType(request));
203+
}
201204
if (canHandle && LoggerUtils.isDiagnosticLogsEnabled()) {
202205
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
203206
getComponentId(), FrameworkConstants.LogConstants.ActionIDs.HANDLE_AUTH_STEP);

components/org.wso2.carbon.identity.application.authenticator.oidc/src/test/java/org/wso2/carbon/identity/application/authenticator/oidc/OpenIDConnectAuthenticatorTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ public void testCanHandle(String grantType, String state, String loginType, Stri
256256

257257
}
258258

259+
@Test
260+
public void testCanHandleForNativeSDKBasedFederation() throws Exception {
261+
262+
mockStatic(LoggerUtils.class);
263+
when(LoggerUtils.isDiagnosticLogsEnabled()).thenReturn(true);
264+
when(mockServletRequest.getParameter(OIDCAuthenticatorConstants.ACCESS_TOKEN_PARAM)).thenReturn(accessToken);
265+
when(mockServletRequest.getParameter(OIDCAuthenticatorConstants.ID_TOKEN_PARAM)).thenReturn(idToken);
266+
when(mockServletRequest.getParameter(OIDCAuthenticatorConstants.SESSION_DATA_KEY_PARAM))
267+
.thenReturn(sessionDataKey);
268+
269+
assertTrue(openIDConnectAuthenticator.canHandle(mockServletRequest));
270+
assertEquals(openIDConnectAuthenticator.getContextIdentifier(mockServletRequest), sessionDataKey);
271+
}
272+
259273
@Test
260274
public void testGetAuthorizationServerEndpoint() throws IOException {
261275

0 commit comments

Comments
 (0)