Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new endpoints for client protocol mappers #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/Keycloak.Net/Keycloak.Net.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=root/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=scopemappings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=users/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mapperes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=userstorageprovider/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
51 changes: 51 additions & 0 deletions src/Keycloak.Net/ProtocolMappers/KeycloakClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,39 @@ public async Task<bool> CreateProtocolMapperAsync(string realm, string clientSco
return response.IsSuccessStatusCode;
}

public async Task<bool> CreateProtocolMapperByClientIdAsync(string realm, string id, ProtocolMapper protocolMapperRepresentation)
{
var response = await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/clients/{id}/protocol-mappers/models")
.PostJsonAsync(protocolMapperRepresentation)
.ConfigureAwait(false);
return response.IsSuccessStatusCode;
}

public async Task<bool> CreateMultipleProtocolMapperByClientIdAsync(string realm, string id, IEnumerable<ProtocolMapper> protocolMapperRepresentations)
{
var response = await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/clients/{id}/protocol-mappers/models")
.PostJsonAsync(protocolMapperRepresentations)
.ConfigureAwait(false);
return response.IsSuccessStatusCode;
}

public async Task<IEnumerable<ProtocolMapper>> GetProtocolMappersAsync(string realm, string clientScopeId) => await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/client-scopes/{clientScopeId}/protocol-mappers/models")
.GetJsonAsync<IEnumerable<ProtocolMapper>>()
.ConfigureAwait(false);

public async Task<IEnumerable<ProtocolMapper>> GetProtocolMappersByClientIdAsync(string realm, string id) => await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/clients/{id}/protocol-mappers/models")
.GetJsonAsync<IEnumerable<ProtocolMapper>>()
.ConfigureAwait(false);

public async Task<IEnumerable<ProtocolMapper>> GetProtocolMappersByClientIdAsync(string realm, string id, string protocolMapperId) => await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/clients/{id}/protocol-mappers/models/{protocolMapperId}")
.GetJsonAsync<IEnumerable<ProtocolMapper>>()
.ConfigureAwait(false);

public async Task<ProtocolMapper> GetProtocolMapperAsync(string realm, string clientScopeId, string protocolMapperId) => await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/client-scopes/{clientScopeId}/protocol-mappers/models/{protocolMapperId}")
.GetJsonAsync<ProtocolMapper>()
Expand All @@ -44,6 +72,15 @@ public async Task<bool> UpdateProtocolMapperAsync(string realm, string clientSco
return response.IsSuccessStatusCode;
}

public async Task<bool> UpdateProtocolMapperByClientIdAsync(string realm, string id, string protocolMapperId, ProtocolMapper protocolMapperRepresentation)
{
var response = await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/clients/{id}/protocol-mappers/models/{protocolMapperId}")
.PutJsonAsync(protocolMapperRepresentation)
.ConfigureAwait(false);
return response.IsSuccessStatusCode;
}

public async Task<bool> DeleteProtocolMapperAsync(string realm, string clientScopeId, string protocolMapperId)
{
var response = await GetBaseUrl(realm)
Expand All @@ -53,9 +90,23 @@ public async Task<bool> DeleteProtocolMapperAsync(string realm, string clientSco
return response.IsSuccessStatusCode;
}

public async Task<bool> DeleteProtocolMapperByClientIdAsync(string realm, string id, string protocolMapperId)
{
var response = await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/clients/{id}/protocol-mappers/models/{protocolMapperId}")
.DeleteAsync()
.ConfigureAwait(false);
return response.IsSuccessStatusCode;
}

public async Task<IEnumerable<ProtocolMapper>> GetProtocolMappersByNameAsync(string realm, string clientScopeId, string protocol) => await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/client-scopes/{clientScopeId}/protocol-mappers/protocol/{protocol}")
.GetJsonAsync<IEnumerable<ProtocolMapper>>()
.ConfigureAwait(false);

public async Task<IEnumerable<ProtocolMapper>> GetProtocolMappersByClientIdByNameAsync(string realm, string id, string protocol) => await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/clients/{id}/protocol-mappers/protocol/{protocol}")
.GetJsonAsync<IEnumerable<ProtocolMapper>>()
.ConfigureAwait(false);
}
}