forked from Black-Cockpit/NETCore.Keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKcOrganizations.cs
More file actions
141 lines (127 loc) · 4.63 KB
/
KcOrganizations.cs
File metadata and controls
141 lines (127 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Microsoft.Extensions.Logging;
using NETCore.Keycloak.Client.HttpClients.Abstraction;
using NETCore.Keycloak.Client.Models;
using NETCore.Keycloak.Client.Models.Organizations;
namespace NETCore.Keycloak.Client.HttpClients.Implementation;
/// <inheritdoc cref="IKcOrganizations"/>
internal sealed class KcOrganizations(string baseUrl,
ILogger logger) : KcHttpClientBase(logger, baseUrl), IKcOrganizations
{
// Primary constructor on the class declaration is used; no explicit ctor body required.
/// <inheritdoc cref="IKcOrganizations.CreateAsync"/>
public Task<KcResponse<object>> CreateAsync(
string realm,
string accessToken,
KcOrganization organization,
CancellationToken cancellationToken = default)
{
ValidateAccess(realm, accessToken);
ValidateNotNull(nameof(organization), organization);
var url = $"{BaseUrl}/{realm}/organizations";
return ProcessRequestAsync<object>(
url,
HttpMethod.Post,
accessToken,
"Unable to create organization",
organization,
"application/json",
cancellationToken);
}
/// <inheritdoc cref="IKcOrganizations.UpdateAsync"/>
public Task<KcResponse<object>> UpdateAsync(
string realm,
string accessToken,
string organizationId,
KcOrganization organization,
CancellationToken cancellationToken = default)
{
ValidateAccess(realm, accessToken);
ValidateRequiredString(nameof(organizationId), organizationId);
ValidateNotNull(nameof(organization), organization);
var url = $"{BaseUrl}/{realm}/organizations/{organizationId}";
return ProcessRequestAsync<object>(
url,
HttpMethod.Put,
accessToken,
"Unable to update organization",
organization,
"application/json",
cancellationToken);
}
/// <inheritdoc cref="IKcOrganizations.DeleteAsync"/>
public Task<KcResponse<object>> DeleteAsync(
string realm,
string accessToken,
string organizationId,
CancellationToken cancellationToken = default)
{
ValidateAccess(realm, accessToken);
ValidateRequiredString(nameof(organizationId), organizationId);
var url = $"{BaseUrl}/{realm}/organizations/{organizationId}";
return ProcessRequestAsync<object>(
url,
HttpMethod.Delete,
accessToken,
"Unable to delete organization",
null,
"application/json",
cancellationToken);
}
/// <inheritdoc cref="IKcOrganizations.GetAsync"/>
public Task<KcResponse<KcOrganization>> GetAsync(
string realm,
string accessToken,
string organizationId,
CancellationToken cancellationToken = default)
{
ValidateAccess(realm, accessToken);
ValidateRequiredString(nameof(organizationId), organizationId);
var url = $"{BaseUrl}/{realm}/organizations/{organizationId}";
return ProcessRequestAsync<KcOrganization>(
url,
HttpMethod.Get,
accessToken,
"Unable to get organization",
null,
"application/json",
cancellationToken);
}
/// <inheritdoc cref="IKcOrganizations.ListAsync"/>
public Task<KcResponse<IEnumerable<KcOrganization>>> ListAsync(
string realm,
string accessToken,
KcOrganizationFilter filter = null,
CancellationToken cancellationToken = default)
{
ValidateAccess(realm, accessToken);
filter ??= new KcOrganizationFilter();
var url = $"{BaseUrl}/{realm}/organizations{filter.BuildQuery()}";
return ProcessRequestAsync<IEnumerable<KcOrganization>>(
url,
HttpMethod.Get,
accessToken,
"Unable to list organizations",
null,
"application/json",
cancellationToken);
}
/// <inheritdoc cref="IKcOrganizations.CountAsync"/>
public Task<KcResponse<long>> CountAsync(
string realm,
string accessToken,
KcOrganizationFilter filter = null,
CancellationToken cancellationToken = default)
{
ValidateAccess(realm, accessToken);
filter ??= new KcOrganizationFilter();
var url = $"{BaseUrl}/{realm}/organizations/count{filter.BuildQuery()}";
return ProcessRequestAsync<long>(
url,
HttpMethod.Get,
accessToken,
"Unable to count organizations",
null,
"application/json",
cancellationToken);
}
}