8000 Add client OIDC compatibility mode setting for configuring the header type in access tokens. by laurids · Pull Request #37573 · keycloak/keycloak · GitHub
[go: up one dir, main page]

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
8 changes: 8 additions & 0 deletions docs/documentation/release_notes/topics/26_2_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ user storage provider.
The Keycloak outgoing link:{adminguide_email_name}[SMTP mail configuration] now supports token authentication (XOAUTH2).
Many service providers (Microsoft, Google) are moving towards SMTP OAuth authentication and end the support for basic authentication.
The token is gathered using Client Credentials Grant.

= New client configuration for access token header type

A new admin setting has been added: Clients -> Advanced -> Fine grain OpenID Connect configuration -> Use "at+jwt" as access token header type

If enabled, access tokens will get header type `at+jwt` in compliance with https://datatracker.ietf.org/doc/html/rfc9068#section-2.1[rfc9068#section-2.1]. Otherwise, the access token header type will be `JWT`.

This setting is turned off by default.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ authnContextClassRefsHelp=Ordered list of requested AuthnContext ClassRefs.
sessionsType.directGrant=Direct grant
validateSignature=Validate Signatures
useLowerCaseBearerType=Use lower-case bearer type in token responses
useRfc9068AccessTokenType=Use "at+jwt" as access token header type
headers=Headers
ldapAttributeNameHelp=Name of the LDAP attribute, which will be added to the new user during registration.
createAGroup=Create a group
Expand Down Expand Up @@ -2462,6 +2463,7 @@ revokeRefreshTokenHelp=If enabled, a refresh token can only be used up to 'Refre
nameField=Name
ownerManagedAccessHelp=If enabled, access to this resource can be managed by the resource owner.
useLowerCaseBearerTypeHelp=If this is on, token responses will be set the with the type "bearer" in lower-case. By default, the server sets the type as "Bearer" as defined by RFC6750.
useRfc9068AccessTokenTypeHelp=If enabled, access tokens will get header type "at+jwt" in compliance with RFC9068. Otherwise, the header type will be "JWT".
addCondition=Add condition
updateSuccessClientScope=Client scope updated
connectionAndAuthentication=Connection & Authentication
Expand Down
1 change: 1 addition & 0 deletions js/apps/admin-ui/src/clients/AdvancedTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const AdvancedTab = ({ save, client }: AdvancedProps) => {
"policyUri",
"tosUri",
"access.token.signed.response.alg",
"access.token.header.type.rfc9068",
"id.token.signed.response.alg",
"id.token.encrypted.response.alg",
"id.token.encrypted.response.enc",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProviderRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/serverInfoRepesentation";
import { ActionGroup, Button, FormGroup } from "@patternfly/react-core";
import { ActionGroup, Button, FormGroup, Switch } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import { HelpItem, SelectControl } from "@keycloak/keycloak-ui-shared";
import { FormAccess } from "../../components/form/FormAccess";
Expand All @@ -8,6 +8,7 @@ import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
import { convertAttributeNameToForm, sortProviders } from "../../util";
import { FormFields } from "../ClientDetails";
import { ApplicationUrls } from "./ApplicationUrls";
import { Controller, useFormContext } from "react-hook-form";

type FineGrainOpenIdConnectProps = {
save: () => void;
Expand All @@ -21,6 +22,7 @@ export const FineGrainOpenIdConnect = ({
hasConfigureAccess,
}: FineGrainOpenIdConnectProps) => {
const { t } = useTranslation();
const { control } = useFormContext();
const providers = useServerInfo().providers;
const clientSignatureProviders = providers?.clientSignature.providers;
const contentEncryptionProviders = providers?.contentencryption.providers;
Expand Down Expand Up @@ -63,6 +65,35 @@ export const FineGrainOpenIdConnect = ({
}}
options={prependEmpty(clientSignatureProviders!)}
/>
<FormGroup
label={t("useRfc9068AccessTokenType")}
fieldId="useRfc9068AccessTokenType"
hasNoPaddingTop
labelIcon={
<HelpItem
helpText={t("useRfc9068AccessTokenTypeHelp")}
fieldLabelId="useRfc9068AccessTokenType"
/>
}
>
<Controller
name={convertAttributeNameToForm<FormFields>(
"attributes.access.token.header.type.rfc9068",
)}
defaultValue="false"
control={control}
render={({ field }) => (
<Switch
id="useRfc9068AccessTokenType"
label={t("on")}
labelOff={t("off")}
isChecked={field.value === "true"}
value) => field.onChange(value.toString())}
aria-label={t("useRfc9068AccessTokenType")}
/>
)}
/>
</FormGroup>
<SelectControl
name={convertAttributeNameToForm<FormFields>(
"attributes.id.token.signed.response.alg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ spec:
saml.authnstatement: 'false'
display.on.consent.screen: 'false'
token.response.type.bearer.lower-case: 'false'
access.token.header.type.rfc9068: 'false'
saml.onetimeuse.condition: 'false'
authenticationFlowBindingOverrides: {}
fullScopeAllowed: true
Expand Down
1 change: 1 addition & 0 deletions operator/src/test/resources/token-test-realm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ spec:
saml.authnstatement: 'false'
display.on.consent.screen: 'false'
token.response.type.bearer.lower-case: 'false'
access.token.header.type.rfc9068: 'false'
saml.onetimeuse.condition: 'false'
authenticationFlowBindingOverrides: {}
fullScopeAllowed: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public final class OIDCConfigAttributes {

public static final String USE_LOWER_CASE_IN_TOKEN_RESPONSE = "token.response.type.bearer.lower-case";

public static final String USE_RFC9068_ACCESS_TOKEN_HEADER_TYPE = "access.token.header.type.rfc9068";

public static final String ID_TOKEN_AS_DETACHED_SIGNATURE = "id.token.as.detached.signature";

public static final String AUTHORIZATION_SIGNED_RESPONSE_ALG = "authorization.signed.response.alg";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ public String encodeAndEncrypt(Token token) {

private String type(TokenCategory category) {
switch (category) {
case ACCESS:
ClientModel client = session.getContext().getClient();
return OIDCAdvancedConfigWrapper.fromClientModel(client).isUseRfc9068AccessTokenHeaderType()
? TokenUtil.TOKEN_TYPE_JWT_ACCESS_TOKEN
: "JWT";
case LOGOUT:
return TokenUtil.TOKEN_TYPE_JWT_LOGOUT_TOKEN;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.keycloak.protocol.oidc;

import static org.keycloak.protocol.oidc.OIDCConfigAttributes.USE_RFC9068_ACCESS_TOKEN_HEADER_TYPE;
import static org.keycloak.protocol.oidc.OIDCConfigAttributes.USE_LOWER_CASE_IN_TOKEN_RESPONSE;

import org.keycloak.authentication.authenticators.client.X509ClientAuthenticator;
Expand Down Expand Up @@ -213,8 +214,16 @@ public boolean isUseLowerCaseInTokenResponse() {
return Boolean.parseBoolean(getAttribute(USE_LOWER_CASE_IN_TOKEN_RESPONSE, "false"));
}

public void setUseLowerCaseInTokenResponse(boolean useRefreshToken) {
setAttribute(USE_LOWER_CASE_IN_TOKEN_RESPONSE, String.valueOf(useRefreshToken));
public void setUseLowerCaseInTokenResponse(boolean useLowerCaseInTokenResponse) {
setAttribute(USE_LOWER_CASE_IN_TOKEN_RESPONSE, String.valueOf(useLowerCaseInTokenResponse));
}

public boolean isUseRfc9068AccessTokenHeaderType() {
return Boolean.parseBoolean(getAttribute(USE_RFC9068_ACCESS_TOKEN_HEADER_TYPE, "false"));
}

public void setUseRfc9068AccessTokenHeaderType(boolean useRfc9068AccessTokenHeaderType) {
setAttribute(USE_RFC9068_ACCESS_TOKEN_HEADER_TYPE, String.valueOf(useRfc9068AccessTokenHeaderType));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,28 @@ public void testTokenResponseUsingLowerCaseType() throws Exception {
}
}

@Test
public void testTokenResponseUsingRfc9068HeaderType() throws Exception {
ClientsResource clients = realmsResouce().realm("test").clients();
ClientRepresentation client = clients.findByClientId(oauth.getClientId()).get(0);

OIDCAdvancedConfigWrapper.fromClientRepresentation(client).setUseRfc9068AccessTokenHeaderType(true);
clients.get(client.getId()).update(client);

try {
oauth.doLogin("test-user@localhost", "password");

String code = oauth.parseLoginResponse().getCode();
AccessTokenResponse response = oauth.doAccessTokenRequest(code);

JWSHeader header = new JWSInput(response.getAccessToken()).getHeader();
assertEquals("at+jwt", header.getType());
} finally {
OIDCAdvancedConfigWrapper.fromClientRepresentation(client).setUseRfc9068AccessTokenHeaderType(false);
clients.get(client.getId()).update(client);
}
}

// KEYCLOAK-3692
@Test
public void accessTokenWrongCode() throws Exception {
Expand Down
0