Skip to content

Commit e8cc3f9

Browse files
committed
build(csproj): enable multi-targeting for .NET 9 (+ .NET 8) and minor updates
1 parent 3381f42 commit e8cc3f9

File tree

5 files changed

+84
-30
lines changed

5 files changed

+84
-30
lines changed

README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,40 @@
88
[![Language - C#](https://img.shields.io/static/v1?label=Language&message=C%23&color=blueviolet)](https://dotnet.microsoft.com/it-it/languages/csharp)
99
[![stars - pdnd-client-assertion-generator](https://img.shields.io/github/stars/italia/pdnd-client-assertion-generator?style=social)](https://github.com/italia/pdnd-client-assertion-generator)
1010

11-
.NET implementation of **OAuth2** authentication for **PDND** service with client assertion generation.
11+
A .NET implementation of **OAuth 2.0** client authentication for **PDND** (Piattaforma Digitale Nazionale Dati), including client assertion (JWT) generation and voucher retrieval.
1212

1313
## Contents
14-
- [PDND](#pdnd)
14+
- [What is PDND?](#what-is-pdnd)
1515
- [Voucher](#voucher)
1616
- [Requesting a Voucher](#requesting-a-voucher)
1717
- [How to Use the Client Assertion Generator](#how-to-use-the-client-assertion-generator)
18-
- [Licensee](#licensee)
18+
- [Voucher Flow for Interoperability APIs](#voucher-flow-for-interoperability-apis)
19+
- [Security Notes](#security-notes)
20+
- [License](#license)
1921
- [Contact](#contact)
2022

21-
## PDND
23+
## What is PDND?
2224
The **[Piattaforma Digitale Nazionale Dati (PDND)](https://developers.italia.it/it/pdnd/)** is an Italian digital infrastructure designed to facilitate **data interoperability** and exchange between public administrations and private entities. The platform aims to simplify the sharing of public data by providing a secure, standardized, and centralized system for data integration, access, and management. PDND promotes digital transformation within the public sector by ensuring data is accessible, reliable, and reusable, enabling more efficient public services, enhancing transparency, and supporting **data-driven decision-making** for both government and citizens.
2325

2426
## Voucher
25-
Vouchers are simple JWT tokens. The implemented authentication flow is OAuth 2.0, which refers to [**RFC6750**](https://datatracker.ietf.org/doc/html/rfc6750) for the use of Bearer tokens and to [**RFC7521**](https://datatracker.ietf.org/doc/html/rfc7521) for client authorization via client assertion.
27+
A **voucher** is a JWT used as a Bearer token to access PDND Interoperability APIs.
28+
29+
This library implements the OAuth 2.0 flow with:
30+
31+
- [**RFC6750**](https://datatracker.ietf.org/doc/html/rfc6750) (Bearer tokens)
32+
- [**RFC7521**](https://datatracker.ietf.org/doc/html/rfc7521) (client authorization via client assertion)
33+
34+
To request a voucher, the client must:
35+
1. Register at least one public key on the PDND client.
36+
2. Create a client assertion (JWT) and sign it with the corresponding private key.
37+
3. Exchange the assertion for a voucher at the authorization endpoint.
2638

2739
## Requesting a Voucher
2840
To obtain a valid voucher, you must first upload at least one public key to an interop API client. The first step is to create a valid client assertion and sign it with your private key (which must match the public key registered with the client on PDND Interoperabilità). The client assertion consists of a header and a payload.
2941

3042
## Voucher Flow for Interoperability APIs
31-
The user requests a voucher. Once obtained, they include it as an authorization header in subsequent calls to the PDND Interoperability APIs.
43+
1. Your system requests a voucher using a signed client assertion.
44+
2. On success, include the returned voucher in the Authorization: Bearer <token> header when calling PDND Interoperability APIs.
3245

3346
## How to Use the Client Assertion Generator
3447
To properly set up and use the Client Assertion Generator in your ASP.NET Core application, follow these steps:
@@ -39,14 +52,14 @@ To properly set up and use the Client Assertion Generator in your ASP.NET Core a
3952
"ServerUrl": "https://test-server-url.com",
4053
"KeyId": "ZmYxZGE2YjQtMzY2Yy00NWI5LThjNGItMDJmYmQyZGIyMmZh",
4154
"Algorithm": "RS256",
42-
"Type": "at+jwt",
55+
"Type": "JWT",
4356
"ClientId": "9b361d49-33f4-4f1e-a88b-4e12661f2309",
4457
"Issuer": "interop.pagopa.it",
4558
"Subject": "9b361d49-33f4-4f1e-a88b-4e12661f2309",
4659
"Audience": "https://erogatore.example/ente-example/v1",
4760
"PurposeId": "1b361d49-33f4-4f1e-a88b-4e12661f2300",
4861
"KeyPath": "C:/Keys/private.pem",
49-
"Duration": "600"
62+
"Duration": "600" // Duration is expressed in milliseconds
5063
},
5164
```
5265

@@ -81,7 +94,13 @@ If you'd like to contribute, please fork, fix, commit and send a pull request fo
8194
* [Fork the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)
8295
* [Open an issue](https://github.com/italia/pdnd-client-assertion-generator/issues) if you encounter a bug or have a suggestion for improvements/features
8396

84-
## Licensee
97+
## Security Notes
98+
- Never commit private keys or secrets to the repository.
99+
- Prefer environment variables or secret stores for sensitive values.
100+
- Rotate keys regularly and restrict file permissions on KeyPath.
101+
- Validate token lifetimes appropriate to your risk profile.
102+
103+
## License
85104
Repository source code is available under MIT License, see license in the source.
86105

87106
## Contact

src/PDNDClientAssertionGenerator.Api/PDNDClientAssertionGenerator.Api.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.8" />
12-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.8" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.8" />
14-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
15-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.8" />
16-
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
14+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
15+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.9" />
16+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

src/PDNDClientAssertionGenerator.Api/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ServerUrl": "https://test-server-url.com",
44
"KeyId": "ZmYxZGE2YjQtMzY2Yy00NWI5LThjNGItMDJmYmQyZGIyMmZh",
55
"Algorithm": "RS256",
6-
"Type": "at+jwt",
6+
"Type": "JWT",
77
"ClientId": "9b361d49-33f4-4f1e-a88b-4e12661f2309",
88
"Issuer": "interop.pagopa.it",
99
"Subject": "9b361d49-33f4-4f1e-a88b-4e12661f2309",
Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<!-- Multi-targeting: build for both .NET 8 (LTS) and .NET 9 (STS) -->
5+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
6+
7+
<!-- Enable modern C# conveniences and nullable reference types -->
58
<ImplicitUsings>enable</ImplicitUsings>
69
<Nullable>enable</Nullable>
10+
11+
<!-- NuGet package metadata -->
712
<Description>.NET Client Assertion Generator for PDND Service API </Description>
813
<PackageProjectUrl>https://github.com/italia/pdnd-client-assertion-generator</PackageProjectUrl>
914
<RepositoryUrl>https://github.com/italia/pdnd-client-assertion-generator</RepositoryUrl>
1015
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1116
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1217
<Title>.NET Client Assertion Generator for PDND Service API</Title>
1318
<PackageReadmeFile>README.md</PackageReadmeFile>
14-
<Version>1.0.4</Version>
15-
<AssemblyVersion></AssemblyVersion>
19+
<Version>1.0.4</Version>
20+
21+
<!-- Optional: set AssemblyVersion explicitly or remove the element -->
22+
<!-- <AssemblyVersion>1.0.4.0</AssemblyVersion> -->
23+
24+
<!-- Package author(s) -->
1625
<Authors>Francesco Del Re</Authors>
1726
</PropertyGroup>
1827

28+
<!-- Package assets to include in the NuGet package root -->
1929
<ItemGroup>
2030
<None Include="..\..\LICENSE">
2131
<Pack>True</Pack>
@@ -27,17 +37,42 @@
2737
</None>
2838
</ItemGroup>
2939

30-
<ItemGroup>
31-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.8" />
32-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.8" />
33-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.8" />
34-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.8" />
35-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.8" />
36-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.8" />
37-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.8" />
40+
<!-- Dependencies for .NET 8 -->
41+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
42+
<!-- Microsoft.Extensions stack aligned to .NET 8 -->
43+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
44+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
45+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
46+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.9" />
47+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
48+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
49+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.9" />
50+
51+
<!-- IdentityModel packages (same versions across TFMs for consistency) -->
3852
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
3953
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
40-
<PackageReference Include="System.Text.Json" Version="9.0.8" />
54+
55+
<!-- System.Text.Json aligned to .NET 8 -->
56+
<PackageReference Include="System.Text.Json" Version="9.0.9" />
57+
</ItemGroup>
58+
59+
<!-- Dependencies for .NET 9 -->
60+
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
61+
<!-- Microsoft.Extensions stack aligned to .NET 9 -->
62+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
63+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
64+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
65+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.9" />
66+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
67+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
68+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.9" />
69+
70+
<!-- IdentityModel packages (same versions across TFMs for consistency) -->
71+
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
72+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
73+
74+
<!-- System.Text.Json aligned to .NET 9 -->
75+
<PackageReference Include="System.Text.Json" Version="9.0.9" />
4176
</ItemGroup>
4277

43-
</Project>
78+
</Project>

src/PDNDClientAssertionGenerator/Services/OAuth2Service.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task<string> GenerateClientAssertionAsync(CancellationToken ct = de
4040

4141
// Define the current UTC time and the token expiration time.
4242
DateTime issuedAt = DateTime.UtcNow;
43-
DateTime expiresAt = issuedAt.AddMinutes(_config.Duration);
43+
DateTime expiresAt = issuedAt.AddSeconds(_config.Duration);
4444

4545
// Define JWT header as a dictionary of key-value pairs.
4646
Dictionary<string, string> headers = new()

0 commit comments

Comments
 (0)