Skip to content

Commit

Permalink
feat: move to buf generate and add .net 8.0 (#916)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This makes the Zitadel.Grpc package obsolete.
With buf, all gRPC sources are directly in the Zitadel package.
To migrate, just remove the dependency to Zitadel.Grpc and use
the Zitadel package instead.
  • Loading branch information
buehler authored Jan 24, 2024
1 parent 16bf30a commit 1d28b13
Show file tree
Hide file tree
Showing 60 changed files with 2,875 additions and 2,485 deletions.
398 changes: 398 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ jobs:
semantic-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: bufbuild/buf-setup-action@v1
with:
submodules: true
fetch-depth: 1
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: extractions/setup-just@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x
dotnet-version: 8.x
- name: Setup dotnet tools
run: dotnet tool restore
- name: Generate gRPC code
run: just generate-grpc
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
with:
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ jobs:
version:
- 6.x
- 7.x
- 8.x
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: bufbuild/buf-setup-action@v1
with:
submodules: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: extractions/setup-just@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.version }}
- name: Setup dotnet tools
run: dotnet tool restore
- name: Generate gRPC code
run: just generate-grpc
- name: Test
run: dotnet test --configuration Release

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ bld/
# Testing results
coverage.json
coverage.info

# Generated Stuff
*.g.cs
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
[submodule "external/protoc-gen-validate"]
path = external/protoc-gen-validate
url = https://github.com/envoyproxy/protoc-gen-validate.git
[submodule "external/grpc-gateway"]
path = external/grpc-gateway
url = https://github.com/grpc-ecosystem/grpc-gateway
[submodule "external/googleapis"]
path = external/googleapis
url = https://github.com/googleapis/googleapis
[submodule "external/zitadel"]
path = external/zitadel
url = https://github.com/zitadel/zitadel
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2024 smartive AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

Welcome to the repository of the ZITADEL dotnet libraries.

This repository contains two essential ZITADEL libraries:
This repository contains authentication and resource management for ZITADEL in .NET.
It can be used to create a ASP.NET application (with internal session management)
or WebAPIs with OIDC introspection. Further, the compiled proto resources of the
ZITADEL source repository are included to access the API of ZITADEL and manage resources.

- [ZITADEL](./src/Zitadel)
- [ZITADEL.gRPC](./src/Zitadel.Grpc)

While Zitadel.gRPC is only the compiled proto files from the [ZITADEL source repository](https://github.com/zitadel/zitadel),
the other lib contains various helpers and extensions to support ZITADEL.

Both libraries contain a readme file to document the library and the usage itself
as well as the [examples](./examples) folder which contains several examples
for accessing the [API of ZITADEL](./examples/Zitadel.ApiAccess)
or using it in a [WebApp](./examples/Zitadel.AspNet.AuthN) or
Expand Down
21 changes: 9 additions & 12 deletions Zitadel.sln
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{2462186B-61A8-476C-9674-176570BBEC35}"
ProjectSection(SolutionItems) = preProject
tests\Directory.Build.props = tests\Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{47CEB49C-56A9-4BDF-BC66-54E407391D49}"
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zitadel", "src\Zitadel\Zitadel.csproj", "{F6769E50-6690-4E96-8DD7-EA4EB4CDA91C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution", "solution", "{4533ABEB-FB66-4EF8-95D5-FD7F624A95EB}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
README.md = README.md
justfile = justfile
buf.gen.yaml = buf.gen.yaml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{2342B4AF-413F-4A67-80D5-3EDEF2DA435F}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
config\CodeAnalysis.targets = config\CodeAnalysis.targets
config\Common.targets = config\Common.targets
config\project.ruleset = config\project.ruleset
config\stylecop.json = config\stylecop.json
.releaserc.json = .releaserc.json
.gitmodules = .gitmodules
renovate.json = renovate.json
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zitadel.Test", "tests\Zitadel.Test\Zitadel.Test.csproj", "{44543DC1-97C5-4525-8EE4-16E5389FDF4E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zitadel.Grpc", "src\Zitadel.Grpc\Zitadel.Grpc.csproj", "{78335CF5-C1F0-47D4-A8D1-17FC808FAF50}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{F64814BA-005A-42D8-953C-676D9F814408}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zitadel.AspNet.AuthN", "examples\Zitadel.AspNet.AuthN\Zitadel.AspNet.AuthN.csproj", "{17758FFE-92C6-42D0-917B-EDF11F64BBAA}"
Expand All @@ -44,7 +46,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{F6769E50-6690-4E96-8DD7-EA4EB4CDA91C} = {47CEB49C-56A9-4BDF-BC66-54E407391D49}
{44543DC1-97C5-4525-8EE4-16E5389FDF4E} = {2462186B-61A8-476C-9674-176570BBEC35}
{78335CF5-C1F0-47D4-A8D1-17FC808FAF50} = {47CEB49C-56A9-4BDF-BC66-54E407391D49}
{17758FFE-92C6-42D0-917B-EDF11F64BBAA} = {F64814BA-005A-42D8-953C-676D9F814408}
{5D1B3EA7-ED4F-401C-9362-D825A074CA50} = {F64814BA-005A-42D8-953C-676D9F814408}
{48F68486-4E14-417E-B75D-DECF1ED576A5} = {F64814BA-005A-42D8-953C-676D9F814408}
Expand All @@ -58,10 +59,6 @@ Global
{44543DC1-97C5-4525-8EE4-16E5389FDF4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44543DC1-97C5-4525-8EE4-16E5389FDF4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44543DC1-97C5-4525-8EE4-16E5389FDF4E}.Release|Any CPU.Build.0 = Release|Any CPU
{78335CF5-C1F0-47D4-A8D1-17FC808FAF50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78335CF5-C1F0-47D4-A8D1-17FC808FAF50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78335CF5-C1F0-47D4-A8D1-17FC808FAF50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78335CF5-C1F0-47D4-A8D1-17FC808FAF50}.Release|Any CPU.Build.0 = Release|Any CPU
{17758FFE-92C6-42D0-917B-EDF11F64BBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17758FFE-92C6-42D0-917B-EDF11F64BBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17758FFE-92C6-42D0-917B-EDF11F64BBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
31 changes: 0 additions & 31 deletions Zitadel.sln.DotSettings

This file was deleted.

17 changes: 17 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: v1
managed:
enabled: true
csharp_namespace:

plugins:
- plugin: buf.build/protocolbuffers/csharp
out: src/Zitadel/Api/Generated
opt:
- base_namespace=
- file_extension=.g.cs
- plugin: buf.build/grpc/csharp
out: src/Zitadel/Api/Generated
opt:
- base_namespace=
- no_server
- file_suffix=Grpc.g.cs
14 changes: 0 additions & 14 deletions config/CodeAnalysis.targets

This file was deleted.

66 changes: 33 additions & 33 deletions examples/Zitadel.ApiAccess/Program.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// This file contains two examples:
// 1. An example with a service account "personal access token" to access the ZITADEL API.
// 2. An example with a service account "jwt profile key" to access the ZITADEL API.

using Zitadel.Api;
using Zitadel.Credentials;

const string apiUrl = "https://zitadel-libraries-l8boqa.zitadel.cloud";
const string personalAccessToken = "ge85fvmgTX4XAhjpF0XGpelB2vn9LZanJaqmUQDuf7iTpKVowb44LFl-86pqY2mfJCEoIOk";

// or create the token provider directly:
// new StaticTokenProvider(token)
var client = Clients.AuthService(new(apiUrl, ITokenProvider.Static(personalAccessToken)));
var result = await client.GetMyUserAsync(new());
Console.WriteLine($"User: {result.User}");

var serviceAccount = ServiceAccount.LoadFromJsonString(
@"
{
""type"": ""serviceaccount"",
""keyId"": ""170084658355110145"",
""key"": ""-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAnQisbU4FuLmjLR9I2Q01Rm9Mx6WySat2mbxgmOzu04oXuESI\nyS+RkiimdN0khjqouBftYqtVes7yngMLq3E8hMCwv/kLE+YeXphZXnn8tps8M2gV\n7S//uCp9LooK9qeh0lSkOqIsh0at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b6YPAE\nLGNdqiyeG8o98agdkNIzIh0CgYEAlTGhMPfGRL3UXoNN8vopjEUWXozUmvJ090S/\nJLtZXtKtNBp5cEOJWZT9biVhFeKgCZc8ba7ahA29b/aLs+AnPlrfnJh+qzZhQfHz\ngJ0PSwAbkBs5fFBOaCHppiRlvXuFRemo95m4pcwTPBx7Mj4Xqx4lxij2E2rNVMSy\n4AI4l10CgYBwefqXt8B+D+0EvmhyHk19Tk8/fPelclJUv/IVI59c0F9UMAA2rD1U\nNW6k9251OGU7mQkztluNvl13qtAW/DveOjkFeDJIMzhFjravpLQXhUK4ETnM44YL\nFbClVGJaHYSHgOkNpcN5lYVLoyEvzv9rEPwBqpZRVnwWj6L+/I2L5Q==\n-----END RSA PRIVATE KEY-----\n"",
""userId"": ""170079991923474689""
}");
client = Clients.AuthService(
new(
apiUrl,
ITokenProvider.ServiceAccount(
apiUrl,
serviceAccount,
new() { ApiAccess = true })));
result = await client.GetMyUserAsync(new());
Console.WriteLine($"User: {result.User}");
// This file contains two examples:
// 1. An example with a service account "personal access token" to access the ZITADEL API.
// 2. An example with a service account "jwt profile key" to access the ZITADEL API.

using Zitadel.Api;
using Zitadel.Credentials;

const string apiUrl = "https://zitadel-libraries-l8boqa.zitadel.cloud";
const string personalAccessToken = "ge85fvmgTX4XAhjpF0XGpelB2vn9LZanJaqmUQDuf7iTpKVowb44LFl-86pqY2mfJCEoIOk";

// or create the token provider directly:
// new StaticTokenProvider(token)
var client = Clients.AuthService(new(apiUrl, ITokenProvider.Static(personalAccessToken)));
var result = await client.GetMyUserAsync(new());
Console.WriteLine($"User: {result.User}");

var serviceAccount = ServiceAccount.LoadFromJsonString(
@"
{
""type"": ""serviceaccount"",
""keyId"": ""170084658355110145"",
""key"": ""-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAnQisbU4FuLmjLR9I2Q01Rm9Mx6WySat2mbxgmOzu04oXuESI\nyS+RkiimdN0khjqouBftYqtVes7yngMLq3E8hMCwv/kLE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aQVpeHgZYpKLMPNO/2Nu5Le2/SUHwXKXML3sDk4dNXNGb6YPAE\nLGNdqiyeG8o98agdkNIzIh0CgYEAlTGhMPfGRL3UXoNN8vopjEUWXozUmvJ090S/\nJLtZXtKtNBp5cEOJWZT9biVhFeKgCZc8ba7ahA29b/aLs+AnPlrfnJh+qzZhQfHz\ngJ0PSwAbkBs5fFBOaCHppiRlvXuFRemo95m4pcwTPBx7Mj4Xqx4lxij2E2rNVMSy\n4AI4l10CgYBwefqXt8B+D+0EvmhyHk19Tk8/fPelclJUv/IVI59c0F9UMAA2rD1U\nNW6k9251OGU7mQkztluNvl13qtAW/DveOjkFeDJIMzhFjravpLQXhUK4ETnM44YL\nFbClVGJaHYSHgOkNpcN5lYVLoyEvzv9rEPwBqpZRVnwWj6L+/I2L5Q==\n-----END RSA PRIVATE KEY-----\n"",
""userId"": ""170079991923474689""
}");
client = Clients.AuthService(
new(
apiUrl,
ITokenProvider.ServiceAccount(
apiUrl,
serviceAccount,
new() { ApiAccess = true })));
result = await client.GetMyUserAsync(new());
Console.WriteLine($"User: {result.User}");
32 changes: 16 additions & 16 deletions examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Zitadel.AspNet.AuthN.Pages;

[Authorize]
public class Authenticated : PageModel
{
public async Task<IActionResult> OnPostAsync()
{
await HttpContext.SignOutAsync();
return RedirectToPage("/Index");
}
}
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Zitadel.AspNet.AuthN.Pages;

[Authorize]
public class Authenticated : PageModel
{
public async Task<IActionResult> OnPostAsync()
{
await HttpContext.SignOutAsync();
return RedirectToPage("/Index");
}
}
Loading

0 comments on commit 1d28b13

Please sign in to comment.