Skip to content

Commit

Permalink
Update packages | Improved key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
engineering87 committed Nov 18, 2024
1 parent 86037b8 commit 1eefc67
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To properly set up and use the Client Assertion Generator in your ASP.NET Core a
1. Configure Client Assertion Settings, an example below:
```xml
"ClientAssertionConfig": {
"ServerUrl": "",
"ServerUrl": "https://test-server-url.com",
"KeyId": "ZmYxZGE2YjQtMzY2Yy00NWI5LThjNGItMDJmYmQyZGIyMmZh",
"Algorithm": "RS256",
"Type": "at+jwt",
Expand All @@ -45,7 +45,7 @@ To properly set up and use the Client Assertion Generator in your ASP.NET Core a
"Subject": "9b361d49-33f4-4f1e-a88b-4e12661f2309",
"Audience": "https://erogatore.example/ente-example/v1",
"PurposeId": "1b361d49-33f4-4f1e-a88b-4e12661f2300",
"KeyPath": "/path/",
"KeyPath": "C:/Keys/private.pem",
"Duration": "600"
},
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/PDNDClientAssertionGenerator.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Subject": "9b361d49-33f4-4f1e-a88b-4e12661f2309",
"Audience": "https://erogatore.example/ente-example/v1",
"PurposeId": "1b361d49-33f4-4f1e-a88b-4e12661f2300",
"KeyPath": "/path/",
"KeyPath": "C:/Keys/private.pem",
"Duration": "600"
},
"Logging": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Extensions.Configuration;
// (c) 2024 Francesco Del Re <francesco.delre.87@gmail.com>
// This code is licensed under MIT license (see LICENSE.txt for details)
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PDNDClientAssertionGenerator.Configuration;
using PDNDClientAssertionGenerator.Interfaces;
Expand All @@ -16,9 +18,11 @@ public static class PDNDClientAssertionServiceExtensions
/// <returns>The updated IServiceCollection instance.</returns>
public static IServiceCollection AddPDNDClientAssertionServices(this IServiceCollection services)
{
// Use ConfigurationManager to load the configuration file (appsettings.json)
// Use ConfigurationManager to load the configuration file (appsettings.json or environment variables)
var configuration = new ConfigurationManager()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) // Load configuration
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();

// Ensure that the configuration contains required sections and values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
<Nullable>enable</Nullable>
<Description>.NET Client Assertion Generator for PDND Service API </Description>
<PackageProjectUrl>https://github.com/italia/pdnd-client-assertion-generator</PackageProjectUrl>
<RepositoryUrl>https://github.com/engineering87/pdnd-client-assertion-generator</RepositoryUrl>
<RepositoryUrl>https://github.com/italia/pdnd-client-assertion-generator</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>.NET Client Assertion Generator for PDND Service API</Title>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<AssemblyVersion></AssemblyVersion>
<Authors>Francesco Del Re</Authors>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,15 +28,16 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.1.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.2.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.1" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

</Project>
11 changes: 10 additions & 1 deletion src/PDNDClientAssertionGenerator/Utils/SecurityUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ public static RSAParameters GetSecurityParameters(string keyPath)
throw new ArgumentException("Key path cannot be null or empty.", nameof(keyPath));
}

// Normalize the key path by removing any trailing directory or alternative directory separators
string normalizedPath = keyPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

// Check if the key file exists at the specified path
if (!File.Exists(normalizedPath))
{
throw new FileNotFoundException($"The specified key file does not exist at the path: {keyPath}");
}

// Read the PEM content from the specified file
string pemContent;
try
{
pemContent = File.ReadAllText(keyPath).Trim();
pemContent = File.ReadAllText(normalizedPath).Trim();
}
catch (Exception ex)
{
Expand Down

0 comments on commit 1eefc67

Please sign in to comment.