Protocol Mappers Manager¶
Protocol Mapper Class¶
The class Protocol Mapper is a
Protocol Mapper Representation.
To use Protocol Mapper Manager, you need to pass the Realm that you will work with.
We two protocol mappers managers currently, one on Protocol MappersManager and other at Protocol MapperScopesManager.
| Class | File |
|---|---|
KeycloakAdmin\ProtocolMappers\ProtocolMapper |
src/ProtocolMappers/ProtocolMapper.php |
List Protocol Mappers¶
This method returns a collection of Protocol Mappers of specific client (client scope or client).
Usage¶
public function listProtocolMappers()
{
$collectionOfProtocolMappers = $this->admin
->client('my-realm')
->protocolMappers('myClientId')
->list();
foreach ($collectionOfProtocolMappers as $realm) {
var_dump($realm->getProtocol Mapper());
}
}
Save Protocol Mapper¶
This method returns will save a new Protocol Mapper on specific client (Client scope or client).
Usage¶
public function createProtocolMapper(string $id, string $name)
{
$data = [
'id' => $id,
'name' => $name
];
$realm = $this->admin
->client('my-realm')
->protocolMappers('myClientId')
->createFromArray($data)
->save();
}
Show Protocol Mapper¶
This method returns a Protocol Mapper, you need to pass the parameter realmName, id of client and must pass the $id of Protocol Mapper.
If Protocol Mapper was not found, you will receive an Exception.
Usage¶
public function showProtocolMapper(string $id) : ProtocolMapper
{
return $this->admin
->client('myRealm')
->protocolMappers('myClientId')
->show($id);
}
Update Protocol Mapper¶
This method will update a Protocol Mapper, an instance of Protocol Mapper must be created
before call to update. This expects at least id to can update.
In this Library, you can’t update the Protocol Mapper id.
Usage¶
public function update(string $id, array $params = []) : Protocol Mapper
{
$data = [
'id' => $id
] + $params;
return $this->admin-
->client('myRealm')
->protocolMappers('myClientId')
->createFromArray($data)
->update();
}
Delete Protocol Mapper¶
This method will delete a Protocol Mapper, idOfProtocol Mapper must be passed as parameter.
If an error occurs you will receive an Exception otherwise, this
is a void method
Usage¶
public function delete(string $id)
{
try {
$this->admin
->client('myRealm')
->protocolMappers('myClientId')
->delete($id);
} catch (\Exception $e) {
var_dump('cant delete this Protocol Mapper, ' . $e->getMessage());
}
}