Skip to content

Commit

Permalink
feat(jans-auth-server): do not process request if token exchange gran…
Browse files Browse the repository at this point in the history
…t type is not present

Native SSO

#2518
  • Loading branch information
yuriyz committed Oct 25, 2022
1 parent 17a931e commit 69b0731
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public enum GrantType implements HasParamName, AttributeEnum {
*/
OXAUTH_UMA_TICKET("urn:ietf:params:oauth:grant-type:uma-ticket"),

/**
* Token exchange grant type for OAuth 2.0
*/
TOKEN_EXCHANGE("urn:ietf:params:oauth:grant-type:token-exchange"),

/**
* CIBA (Client Initiated Backchannel Authentication) Grant Type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.jans.as.common.util.RedirectUri;
import io.jans.as.model.authorize.AuthorizeErrorResponseType;
import io.jans.as.model.authorize.AuthorizeResponseParam;
import io.jans.as.model.common.GrantType;
import io.jans.as.model.common.Prompt;
import io.jans.as.model.common.ResponseMode;
import io.jans.as.model.common.ScopeConstants;
Expand Down Expand Up @@ -110,6 +111,10 @@ public void addDeviceSecretToSession(AuthzRequest authzRequest, SessionId sessio
if (!Arrays.asList(authzRequest.getScope().split(" ")).contains(ScopeConstants.DEVICE_SSO)) {
return;
}
if (!ArrayUtils.contains(authzRequest.getClient().getGrantTypes(), GrantType.TOKEN_EXCHANGE)) {
log.debug("Skip device secret. Scope has {} value but client does not have Token Exchange Grant Type enabled ('urn:ietf:params:oauth:grant-type:token-exchange')", ScopeConstants.DEVICE_SSO);
return;
}

final String newDeviceSecret = HandleTokenFactory.generateHandleToken();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public Response requestAccessToken(String grantType, String code,
return processCIBA(scope, authReqId, idTokenPreProcessing, executionContext);
} else if (gt == GrantType.DEVICE_CODE) {
return processDeviceCodeGrantType(executionContext, deviceCode, scope);
} else if (gt == GrantType.TOKEN_EXCHANGE) {
return processTokenExchange(code, scope, executionContext);
}
} catch (WebApplicationException e) {
throw e;
Expand All @@ -211,6 +213,11 @@ public Response requestAccessToken(String grantType, String code,
throw new WebApplicationException(tokenRestWebServiceValidator.error(400, TokenErrorResponseType.UNSUPPORTED_GRANT_TYPE, "Unsupported Grant Type.").build());
}

private Response processTokenExchange(String code, String scope, ExecutionContext executionContext) {
// todo
return null;
}

private Response processROPC(String username, String password, String scope, GrantType gt, Function<JsonWebResponse, Void> idTokenPreProcessing, ExecutionContext executionContext) throws SearchException {
boolean authenticated = false;
User user = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.jans.as.server.authorize.ws.rs;

import io.jans.as.common.model.registration.Client;
import io.jans.as.common.model.session.SessionId;
import io.jans.as.common.util.RedirectUri;
import io.jans.as.model.common.GrantType;
import io.jans.as.model.config.WebKeysConfiguration;
import io.jans.as.model.configuration.AppConfiguration;
import io.jans.as.model.crypto.AbstractCryptoProvider;
Expand Down Expand Up @@ -69,9 +71,13 @@ public class AuthzRequestServiceTest {

@Test
public void addDeviceSecretToSession_withoutDeviceSsoScope_shouldNotGenerateDeviceSecret() {
Client client = new Client();
client.setGrantTypes(new GrantType[] { GrantType.AUTHORIZATION_CODE, GrantType.TOKEN_EXCHANGE});

AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setScope("openid");
authzRequest.setRedirectUriResponse(new RedirectUriResponse(mock(RedirectUri.class), "", mock(HttpServletRequest.class), mock(ErrorResponseFactory.class)));
authzRequest.setClient(client);

SessionId sessionId = new SessionId();

Expand All @@ -81,9 +87,13 @@ public void addDeviceSecretToSession_withoutDeviceSsoScope_shouldNotGenerateDevi

@Test
public void addDeviceSecretToSession_withDeviceSsoScope_shouldGenerateDeviceSecret() {
Client client = new Client();
client.setGrantTypes(new GrantType[] { GrantType.AUTHORIZATION_CODE, GrantType.TOKEN_EXCHANGE});

AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setRedirectUriResponse(new RedirectUriResponse(mock(RedirectUri.class), "", mock(HttpServletRequest.class), mock(ErrorResponseFactory.class)));
authzRequest.setScope("openid device_sso");
authzRequest.setClient(client);

SessionId sessionId = new SessionId();

Expand All @@ -92,4 +102,21 @@ public void addDeviceSecretToSession_withDeviceSsoScope_shouldGenerateDeviceSecr
assertEquals(1, sessionId.getDeviceSecrets().size());
assertTrue(StringUtils.isNotBlank(sessionId.getDeviceSecrets().get(0)));
}

@Test
public void addDeviceSecretToSession_withClientWithoutTokenExchangeGrantType_shouldNotGenerateDeviceSecret() {
Client client = new Client();
client.setGrantTypes(new GrantType[] { GrantType.AUTHORIZATION_CODE});

AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setRedirectUriResponse(new RedirectUriResponse(mock(RedirectUri.class), "", mock(HttpServletRequest.class), mock(ErrorResponseFactory.class)));
authzRequest.setScope("openid device_sso");
authzRequest.setClient(client);

SessionId sessionId = new SessionId();

assertTrue(sessionId.getDeviceSecrets().isEmpty());
authzRequestService.addDeviceSecretToSession(authzRequest, sessionId);
assertTrue(sessionId.getDeviceSecrets().isEmpty());
}
}

0 comments on commit 69b0731

Please sign in to comment.