Skip to content

Commit

Permalink
feat: add v2 beta clients from gRPC (#918)
Browse files Browse the repository at this point in the history
* add new clients

* please the upgraded linter

* update renove file
  • Loading branch information
buehler authored Jan 26, 2024
1 parent 921a32a commit 7ede9c3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 25 deletions.
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>smartive/renovate-config", "github>smartive/renovate-config:with-submodules", ":disableMajorUpdates"]
"extends": ["github>smartive/renovate-config", ":disableMajorUpdates"]
}
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
<ItemGroup>
<PackageReference
Include="StyleCop.Analyzers"
Version="1.2.0-beta.507"
Version="1.2.0-beta.556"
PrivateAssets="all"
Condition="$(MSBuildProjectExtension) == '.csproj'" />
<PackageReference
Include="SonarAnalyzer.CSharp"
Version="9.17.0.82934"
PrivateAssets="all"
Condition="$(MSBuildProjectExtension) == '.csproj'" />
<PackageReference Include="Roslynator.Analyzers" Version="4.9.0" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" Version="4.10.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
70 changes: 62 additions & 8 deletions src/Zitadel/Api/Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
using Zitadel.Auth.V1;
using Zitadel.Authentication;
using Zitadel.Management.V1;
using Zitadel.Oidc.V2beta;
using Zitadel.Org.V2beta;
using Zitadel.Session.V2beta;
using Zitadel.Settings.V2beta;
using Zitadel.System.V1;
using Zitadel.User.V2beta;

namespace Zitadel.Api;

Expand All @@ -13,14 +19,6 @@ namespace Zitadel.Api;
/// </summary>
public static class Clients
{
/// <summary>
/// Create a service client for the auth service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="Auth.V1.AuthService.AuthServiceClient"/>.</returns>
public static AuthService.AuthServiceClient AuthService(Options options) =>
GetClient<AuthService.AuthServiceClient>(options);

/// <summary>
/// Create a service client for the admin service.
/// </summary>
Expand All @@ -29,6 +27,14 @@ public static AuthService.AuthServiceClient AuthService(Options options) =>
public static AdminService.AdminServiceClient AdminService(Options options) =>
GetClient<AdminService.AdminServiceClient>(options);

/// <summary>
/// Create a service client for the auth service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="Auth.V1.AuthService.AuthServiceClient"/>.</returns>
public static AuthService.AuthServiceClient AuthService(Options options) =>
GetClient<AuthService.AuthServiceClient>(options);

/// <summary>
/// Create a service client for the management service.
/// </summary>
Expand All @@ -37,6 +43,54 @@ public static AdminService.AdminServiceClient AdminService(Options options) =>
public static ManagementService.ManagementServiceClient ManagementService(Options options) =>
GetClient<ManagementService.ManagementServiceClient>(options);

/// <summary>
/// Create a service client for the oidc service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="OIDCService.OIDCServiceClient"/>.</returns>
public static OIDCService.OIDCServiceClient OidcService(Options options) =>
GetClient<OIDCService.OIDCServiceClient>(options);

/// <summary>
/// Create a service client for the organization service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="OrganizationService.OrganizationServiceClient"/>.</returns>
public static OrganizationService.OrganizationServiceClient OrganizationService(Options options) =>
GetClient<OrganizationService.OrganizationServiceClient>(options);

/// <summary>
/// Create a service client for the session service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="SessionService.SessionServiceClient"/>.</returns>
public static SessionService.SessionServiceClient SessionService(Options options) =>
GetClient<SessionService.SessionServiceClient>(options);

/// <summary>
/// Create a service client for the settings service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="SettingsService.SettingsServiceClient"/>.</returns>
public static SettingsService.SettingsServiceClient SettingsService(Options options) =>
GetClient<SettingsService.SettingsServiceClient>(options);

/// <summary>
/// Create a service client for the system service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="SystemService.SystemServiceClient"/>.</returns>
public static SystemService.SystemServiceClient SystemService(Options options) =>
GetClient<SystemService.SystemServiceClient>(options);

/// <summary>
/// Create a service client for the user service.
/// </summary>
/// <param name="options">Options for the client like authorization method.</param>
/// <returns>The <see cref="UserService.UserServiceClient"/>.</returns>
public static UserService.UserServiceClient UserService(Options options) =>
GetClient<UserService.UserServiceClient>(options);

private static TClient GetClient<TClient>(Options options)
where TClient : ClientBase<TClient>
{
Expand Down
24 changes: 10 additions & 14 deletions src/Zitadel/Credentials/ServiceAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ namespace Zitadel.Credentials
/// </summary>
public record ServiceAccount
{
private static readonly HttpClient HttpClient = new();

/// <summary>
/// The key type.
/// </summary>
public const string Type = "serviceaccount";

private static readonly HttpClient HttpClient = new();

/// <summary>
/// The user id associated with this service account.
/// </summary>
Expand Down Expand Up @@ -204,10 +204,7 @@ private async Task<string> GetSignedJwtAsync(string audience)
},
rsa,
JwsAlgorithm.RS256,
new Dictionary<string, object>
{
{ "kid", KeyId },
});
new Dictionary<string, object> { { "kid", KeyId }, });
}

private async Task<RSAParameters> GetRsaParametersAsync()
Expand All @@ -225,12 +222,6 @@ private async Task<RSAParameters> GetRsaParametersAsync()
return DotNetUtilities.ToRSAParameters(keyPair.Private as RsaPrivateCrtKeyParameters);
}

private sealed record AccessTokenResponse
{
[JsonPropertyName("access_token")]
public string AccessToken { get; init; } = string.Empty;
}

/// <summary>
/// Options for the authentication with a <see cref="ServiceAccount"/>.
/// </summary>
Expand Down Expand Up @@ -283,8 +274,7 @@ internal string CreateOidcScopes() =>
' ',
new[]
{
"openid",
ApiAccess
"openid", ApiAccess
? ApiAccessScope
: string.Empty,
}
Expand All @@ -293,5 +283,11 @@ internal string CreateOidcScopes() =>
.Union(RequiredRoles.Select(r => $"urn:zitadel:iam:org:project:role:{r}"))
.Where(s => !string.IsNullOrWhiteSpace(s)));
}

private sealed record AccessTokenResponse
{
[JsonPropertyName("access_token")]
public string AccessToken { get; init; } = string.Empty;
}
}
}

0 comments on commit 7ede9c3

Please sign in to comment.