Repository navigation
Replies: 2 comments 2 replies
|
I think this is by design, though I agree the UX around it is confusing. When a user belongs to a single org, Keycloak can unambiguously include it in the token. With multiple orgs, Keycloak doesn't know which org context the client wants, so it probably drops them from the default claims to avoid leaking org membership across clients that shouldn't see it. The The comparison with If you want all clients to always get the full org list without requesting the scope explicitly, I believe you can add the |
|
I tested this on Keycloak 26.8.2 with one user in two organizations (
Things that do not work, all tested:
The built-in mapper only acts when the request carries one of the organization scope values ( What does work is a small custom mapper that asks the organization provider for every membership: public class AllOrganizationsMapper extends AbstractOIDCProtocolMapper
implements OIDCAccessTokenMapper, OIDCIDTokenMapper, UserInfoTokenMapper, TokenIntrospectionTokenMapper {
public static final String ID = "oidc-all-organizations-mapper";
private static final List<ProviderConfigProperty> PROPS = new ArrayList<>();
static {
OIDCAttributeMapperHelper.addTokenClaimNameConfig(PROPS);
OIDCAttributeMapperHelper.addIncludeInTokensConfig(PROPS, AllOrganizationsMapper.class);
}
@Override public String getId() { return ID; }
@Override public String getDisplayType() { return "All organizations"; }
@Override public String getDisplayCategory() { return TOKEN_MAPPER_CATEGORY; }
@Override public String getHelpText() { return "Every organization the user is a member of."; }
@Override public List<ProviderConfigProperty> getConfigProperties() { return PROPS; }
@Override
protected void setClaim(IDToken token, ProtocolMapperModel model, UserSessionModel userSession,
KeycloakSession session, ClientSessionContext ctx) {
OrganizationProvider orgs = session.getProvider(OrganizationProvider.class);
if (orgs == null || !orgs.isEnabled()) return;
List<String> aliases = orgs.getByMember(userSession.getUser())
.map(OrganizationModel::getAlias).sorted().toList();
if (aliases.isEmpty()) return;
token.getOtherClaims().put(
model.getConfig().getOrDefault(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, "organizations"), aliases);
}
}Register it in One caution: this exposes every membership to every client that gets the scope, which is the leak the scoped design avoids. So I would attach it as a default scope only on the clients that really need the full list, not realm-wide. |
Uh oh!
There was an error while loading. Please reload this page.
It seems I can get a single organization in the JWT by default when a user is part of one organization by making sure there is a client scope and mapper set to appear by default. When the user is part of two organizations, the organization(s) disappear from the JWT. The accepted solution seems to be to require each and every client to request
organization:*scope (or whatever the name of your client scope is named plus the colon plus the asterisk).I do not understand why this must be so. For example, before and after the introduction of organizations, other plural attributes were/are available by default in the JWT without a
:*, such as:All of
allowed-origins,roles, androlesare a single word in the plural form without requiring clients to requestallowed-origin:*orrole:*.Is there a way to get multiple organization by default without requiring all clients to request them in the form
organization:*and if not, is there a reason (other than time/effort) this couldn't be supported in a future version of Keycloak?I reviewed the past tickets listed here but this still seems like a bug to me.
All reactions