Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ revert=Revert
eventTypes.IDENTITY_PROVIDER_RETRIEVE_TOKEN.description=Identity provider retrieve token
dependentPermission=Dependent permission
disableNonce=Disable nonce
disableTypeClaimCheck=Disable type claim check
addAssociatedRolesSuccess=Associated roles have been added
groupDeleted_one=Group deleted
userHelp=Optionally select user, for whom the example access token will be generated. If you do not select a user, example access token will not be generated during evaluation.
Expand Down Expand Up @@ -2829,6 +2830,7 @@ eventTypes.OAUTH2_DEVICE_CODE_TO_TOKEN.name=OAuth2 device code to token
searchGroups=Search groups
trusted-hosts.tooltip=List of Hosts, which are trusted and are allowed to invoke Client Registration Service and/or be used as values of Client URIs. You can use hostnames or IP addresses. If you use star at the beginning (for example '*.example.com' ) then whole domain example.com will be trusted.
disableNonceHelp=Do not send the nonce parameter in the authentication request. The nonce parameter is sent and verified by default.
disableTypeClaimCheckHelp=Disables the validation of the `typ` claim of tokens received from the Identity Provider. If this is `off` the type claim is validated (default).
deleteClientProfile=Delete this client profile
none=None
type=Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export const ExtendedNonDiscoverySettings = () => {
/>
<SwitchField field="config.disableUserInfo" label="disableUserInfo" />
<SwitchField field="config.disableNonce" label="disableNonce" />
<SwitchField
field="config.disableTypeClaimCheck"
label="disableTypeClaimCheck"
/>
<TextField field="config.defaultScope" label="scopes" />
<FormGroupField label="prompt">
<Controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ final protected BrokeredIdentityContext validateJwt(EventBuilder event, String s
}

try {
if (!isTokenTypeSupported(parsedToken)) {
if (!getConfig().isDisableTypeClaimCheck() && !isTokenTypeSupported(parsedToken)) {
throw new ErrorResponseException(OAuthErrorException.INVALID_TOKEN, "token type not supported", Response.Status.BAD_REQUEST);
}
boolean idTokenType = OAuth2Constants.ID_TOKEN_TYPE.equals(subjectTokenType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ public int getAllowedClockSkew() {
}
}

public boolean isDisableTypeClaimCheck() {
return Boolean.parseBoolean(getConfig().get("disableTypeClaimCheck"));
}

public void setDisableTypeClaimCheck(boolean disableTypeClaimCheck) {
if (disableTypeClaimCheck) {
getConfig().put("disableTypeClaimCheck", Boolean.TRUE.toString());
} else {
getConfig().remove("disableTypeClaimCheck");
}
}

@Override
public void validate(RealmModel realm) {
super.validate(realm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,62 @@ public void testSupportedTokenTypesWhenValidatingSubjectToken() throws Exception
}
}

@Test
public void testIgnoredTokenTypesValidationWhenExplicitlyConfigured() throws Exception {
testingClient.server(BrokerTestConstants.REALM_CONS_NAME).run(KcOidcBrokerTokenExchangeTest::setupRealm);
RealmResource providerRealm = realmsResouce().realm(bc.providerRealmName());
ClientsResource clients = providerRealm.clients();
ClientRepresentation brokerApp = clients.findByClientId("brokerapp").get(0);
brokerApp.setDirectAccessGrantsEnabled(true);
ClientResource brokerAppResource = providerRealm.clients().get(brokerApp.getId());
brokerAppResource.update(brokerApp);
RealmResource consumerRealm = realmsResouce().realm(bc.consumerRealmName());
IdentityProviderResource identityProviderResource = consumerRealm.identityProviders().get(bc.getIDPAlias());
IdentityProviderRepresentation idpRep = identityProviderResource.toRepresentation();
idpRep.getConfig().put("disableUserInfo", "true");
idpRep.getConfig().put("disableTypeClaimCheck", "true");
identityProviderResource.update(idpRep);
getCleanup().addCleanup(() -> {
idpRep.getConfig().put("disableUserInfo", "false");
idpRep.getConfig().put("disableTypeClaimCheck", "false");
identityProviderResource.update(idpRep);
});

org.keycloak.testsuite.util.oauth.AccessTokenResponse tokenResponse = oauth.realm(bc.providerRealmName()).client(brokerApp.getClientId(), brokerApp.getSecret()).doPasswordGrantRequest(bc.getUserLogin(), bc.getUserPassword());
assertThat(tokenResponse.getIdToken(), notNullValue());
String idTokenString = tokenResponse.getIdToken();
oauth.realm(bc.providerRealmName());
oauth.logoutForm().idTokenHint(idTokenString)
.postLogoutRedirectUri(oauth.APP_AUTH_ROOT).open();
String logoutToken = testingClient.testApp().getBackChannelRawLogoutToken();
Assert.assertNotNull(logoutToken);

Client httpClient = AdminClientUtil.createResteasyClient();
try {
WebTarget exchangeUrl = httpClient.target(OAuthClient.AUTH_SERVER_ROOT)
.path("/realms")
.path(bc.consumerRealmName())
.path("protocol/openid-connect/token");
// test user info validation.
try (Response response = exchangeUrl.request()
.header(HttpHeaders.AUTHORIZATION, BasicAuthHelper.createHeader(
"test-app", "secret"))
.post(Entity.form(
new Form()
.param(OAuth2Constants.GRANT_TYPE, OAuth2Constants.TOKEN_EXCHANGE_GRANT_TYPE)
.param(OAuth2Constants.SUBJECT_TOKEN, logoutToken)
.param(OAuth2Constants.SUBJECT_TOKEN_TYPE, OAuth2Constants.JWT_TOKEN_TYPE)
.param(OAuth2Constants.SUBJECT_ISSUER, bc.getIDPAlias())
.param(OAuth2Constants.SCOPE, OAuth2Constants.SCOPE_OPENID)

))) {
assertThat(response.getStatus(), equalTo(Status.OK.getStatusCode()));
}
} finally {
httpClient.close();
}
}

@Test
public void testInternalExternalTokenExchangeSessionToken() throws Exception {
testingClient.server(bc.consumerRealmName()).run(KcOidcBrokerTokenExchangeTest::setupRealm);
Expand Down
Loading