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

feat: upgrade Zitadel Libs and remove old .net version #933

Merged
merged 8 commits into from
Oct 28, 2024
Merged
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
2 changes: 0 additions & 2 deletions .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
fail-fast: true
matrix:
version:
- 6.x
- 7.x
- 8.x
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion examples/Zitadel.ApiAccess/Zitadel.ApiAccess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@page
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Zitadel.AspNet.AuthN.Pages.Authenticated

<!DOCTYPE html>
Expand Down
5 changes: 4 additions & 1 deletion examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

using Zitadel.Authentication;

namespace Zitadel.AspNet.AuthN.Pages;

[Authorize]
public class Authenticated : PageModel
{
public async Task OnPostAsync()
{
await HttpContext.SignOutAsync("Identity.External"); // Options: signs you out of ZITADEL entirely, without this you may not be reprompted for your password.
await HttpContext.SignOutAsync(
"Identity.External"); // Options: signs you out of ZITADEL entirely, without this you may not be reprompted for your password.
await HttpContext.SignOutAsync(
ZitadelDefaults.AuthenticationScheme,
new AuthenticationProperties { RedirectUri = "http://localhost:8080/loggedout" }
Expand Down
2 changes: 1 addition & 1 deletion examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page
@model LoggedOutModel
@model Zitadel.AspNet.AuthN.Pages.LoggedOutModel

<html lang="en">
<head>
Expand Down
12 changes: 5 additions & 7 deletions examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Zitadel.AspNet.AuthN.Pages;

public class LoggedOutModel : PageModel { }
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Zitadel.AspNet.AuthN.Pages;

public class LoggedOutModel : PageModel;
2 changes: 1 addition & 1 deletion examples/Zitadel.AspNet.AuthN/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); });
app.MapRazorPages();

await app.RunAsync();
2 changes: 1 addition & 1 deletion examples/Zitadel.AspNet.AuthN/Zitadel.AspNet.AuthN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
3 changes: 1 addition & 2 deletions examples/Zitadel.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(
endpoints => { endpoints.MapControllers(); });
app.MapControllers();

await app.RunAsync();
2 changes: 1 addition & 1 deletion examples/Zitadel.WebApi/Zitadel.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<LangVersion>12</LangVersion>
<Authors>Christoph Bühler, smartive AG</Authors>
<Authors>Christoph Bühler</Authors>
<Owner>cbuehler</Owner>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand Down
11 changes: 6 additions & 5 deletions src/Zitadel/Api/Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
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.Oidc.V2;
using Zitadel.Org.V2;
using Zitadel.Session.V2;
using Zitadel.Settings.V2;
using Zitadel.System.V1;
using Zitadel.User.V2beta;
using Zitadel.User.V2;

namespace Zitadel.Api;

/// <summary>
/// Helper class to instantiate (gRPC) api service clients for the ZITADEL API with correct settings.
/// All other versions are still available, but the latest version is used by default.
/// </summary>
public static class Clients
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
using System.Security.Claims;

namespace Zitadel.Authentication.Events.Context
{
public class LocalFakeZitadelAuthContext
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="identity">The created ClaimsIdentity.</param>
public LocalFakeZitadelAuthContext(ClaimsIdentity identity)
{
Identity = identity;
}

/// <summary>
/// The created ClaimsIdentity.
/// </summary>
public ClaimsIdentity Identity { get; init; }

/// <summary>
/// The claims of the created ClaimsIdentity.
/// </summary>
public IEnumerable<Claim> Claims => Identity.Claims;

/// <summary>
/// The "user-id" of the fake user.
/// Either set by the options or via HTTP header.
/// </summary>
public string FakeZitadelId => new ClaimsPrincipal(Identity).FindFirstValue("sub")!;

/// <summary>
/// Add a claim to the <see cref="Claims"/> list.
/// This is a convenience method for modifying <see cref="Claims"/>.
/// </summary>
/// <param name="type">Type of the claim (examples: <see cref="ClaimTypes"/>).</param>
/// <param name="value">The value.</param>
/// <param name="valueType">Type of the value (examples: <see cref="ClaimValueTypes"/>).</param>
/// <param name="issuer">The issuer for this claim.</param>
/// <param name="originalIssuer">The original issuer of this claim.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddClaim(
string type,
string value,
string? valueType = null,
string? issuer = null,
string? originalIssuer = null) => AddClaim(new(type, value, valueType, issuer, originalIssuer));

/// <summary>
/// Add a claim to the <see cref="Claims"/> list.
/// This is a convenience method for modifying <see cref="Claims"/>.
/// </summary>
/// <param name="claim">The claim to add.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddClaim(Claim claim)
{
Identity.AddClaim(claim);
return this;
}

/// <summary>
/// Add a single role to the identity's claims.
/// Note: the roles are actually "claims" but this method exists
/// for convenience.
/// </summary>
/// <param name="role">The role to add.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddRole(string role)
{
Identity.AddClaim(new(ClaimTypes.Role, role));
return this;
}

/// <summary>
/// Add multiple roles to the identity's claims.
/// Note: the roles are actually "claims" but this method exists
/// for convenience.
/// </summary>
/// <param name="roles">The roles to add.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddRoles(string[] roles)
{
foreach (var role in roles)
{
AddRole(role);
}

return this;
}
}
}
using System.Security.Claims;
namespace Zitadel.Authentication.Events.Context
{
public class LocalFakeZitadelAuthContext
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="identity">The created ClaimsIdentity.</param>
public LocalFakeZitadelAuthContext(ClaimsIdentity identity)
{
Identity = identity;
}
/// <summary>
/// The created ClaimsIdentity.
/// </summary>
public ClaimsIdentity Identity { get; init; }
/// <summary>
/// The claims of the created ClaimsIdentity.
/// </summary>
public IEnumerable<Claim> Claims => Identity.Claims;
/// <summary>
/// The "user-id" of the fake user.
/// Either set by the options or via HTTP header.
/// </summary>
public string FakeZitadelId => new ClaimsPrincipal(Identity).FindFirstValue("sub")!;
/// <summary>
/// Add a claim to the <see cref="Claims"/> list.
/// This is a convenience method for modifying <see cref="Claims"/>.
/// </summary>
/// <param name="type">Type of the claim (examples: <see cref="ClaimTypes"/>).</param>
/// <param name="value">The value.</param>
/// <param name="valueType">Type of the value (examples: <see cref="ClaimValueTypes"/>).</param>
/// <param name="issuer">The issuer for this claim.</param>
/// <param name="originalIssuer">The original issuer of this claim.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddClaim(
string type,
string value,
string? valueType = null,
string? issuer = null,
string? originalIssuer = null) => AddClaim(new(type, value, valueType, issuer, originalIssuer));
/// <summary>
/// Add a claim to the <see cref="Claims"/> list.
/// This is a convenience method for modifying <see cref="Claims"/>.
/// </summary>
/// <param name="claim">The claim to add.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddClaim(Claim claim)
{
Identity.AddClaim(claim);
return this;
}
/// <summary>
/// Add a single role to the identity's claims.
/// Note: the roles are actually "claims" but this method exists
/// for convenience.
/// </summary>
/// <param name="role">The role to add.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddRole(string role)
{
Identity.AddClaim(new(ClaimTypes.Role, role));
return this;
}
/// <summary>
/// Add multiple roles to the identity's claims.
/// Note: the roles are actually "claims" but this method exists
/// for convenience.
/// </summary>
/// <param name="roles">The roles to add.</param>
/// <returns>The <see cref="LocalFakeZitadelAuthContext"/> for chaining.</returns>
public LocalFakeZitadelAuthContext AddRoles(string[] roles)
{
foreach (var role in roles)
{
AddRole(role);
}
return this;
}
}
}
24 changes: 12 additions & 12 deletions src/Zitadel/Authentication/Events/LocalFakeZitadelEvents.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Zitadel.Authentication.Events.Context;
using Zitadel.Authentication.Handler;

namespace Zitadel.Authentication.Events;

public class LocalFakeZitadelEvents
{
/// <summary>
/// Invoked after a ClaimsIdentity has been generated in the <see cref="LocalFakeZitadelHandler"/>.
/// </summary>
public Func<LocalFakeZitadelAuthContext, Task> OnZitadelFakeAuth { get; set; } = context => Task.CompletedTask;
}
using Zitadel.Authentication.Events.Context;
using Zitadel.Authentication.Handler;
namespace Zitadel.Authentication.Events;
public class LocalFakeZitadelEvents
{
/// <summary>
/// Invoked after a ClaimsIdentity has been generated in the <see cref="LocalFakeZitadelHandler"/>.
/// </summary>
public Func<LocalFakeZitadelAuthContext, Task> OnZitadelFakeAuth { get; set; } = context => Task.CompletedTask;
}
Loading
Loading