Client Scope API
The ClientScopeHandle class provides a fluent API for managing Keycloak client scopes. It allows you to create, update, delete, and retrieve client scopes within a specific realm.
Class: ClientScopeHandle
Constructor
constructor(core: KeycloakAdminClient, realmHandle: RealmHandle, scopeName: string)
- Parameters:
core: An instance ofKeycloakAdminClient.realmHandle: A handle to the realm where the client scope resides.scopeName: The name of the client scope to manage.
Instance Methods
get()
Fetches the client scope by its name and updates the instance's clientScope property.
public async get(): Promise<ClientScopeRepresentation | null>
- Returns: The client scope representation or
nullif the client scope does not exist.
create(data: ClientScopeInputData)
Creates a new client scope.
public async create(data: ClientScopeInputData)
- Parameters:
data: The data for the new client scope.
- Throws: An error if the client scope already exists.
update(data: ClientScopeInputData)
Updates the client scope's details.
public async update(data: ClientScopeInputData)
- Parameters:
data: The updated data for the client scope.
- Throws: An error if the client scope does not exist.
delete()
Deletes the client scope.
public async delete()
- Throws: An error if the client scope does not exist.
ensure(data: ClientScopeInputData)
Ensures the client scope exists. If it does, updates it; otherwise, creates it.
public async ensure(data: ClientScopeInputData)
- Parameters:
data: The data for the client scope.
discard()
Deletes the client scope if it exists.
public async discard()
- Returns: The name of the deleted client scope.
Constants
defaultScopeData
Default data for creating a client scope.
export const defaultScopeData = Object.freeze({
description: '',
type: 'none',
protocol: 'openid-connect',
attributes: {
'display.on.consent.screen': 'true',
'include.in.token.scope': 'false',
'consent.screen.text': '',
'gui.order': '',
},
});
Types
ClientScopeType
The type of the client scope.
export type ClientScopeType = 'none' | 'default' | 'optional';
ClientScopeProtocol
The protocol of the client scope.
export type ClientScopeProtocol = 'openid-connect' | 'saml';
ClientScopeInputData
The input data type for creating or updating a client scope.
export type ClientScopeInputData = Omit<ClientScopeRepresentationExt, 'name | id'>;
ClientScopeRepresentationExt
An extended representation of the client scope.
export interface ClientScopeRepresentationExt extends ClientScopeRepresentation {
type?: ClientScopeType;
protocol?: ClientScopeProtocol;
}
This API provides a comprehensive interface for managing Keycloak client scopes within a specific realm.