Skip to content

Commit c9d1eff

Browse files
Merge pull request #520 from TransactionProcessing/task/#519_duende_removal
Switch to OpenIddict client auth, remove bootstrapper tests
2 parents 6249141 + bca95c7 commit c9d1eff

3 files changed

Lines changed: 20 additions & 95 deletions

File tree

EstateReportingAPI.Tests/General/BootstrapperTests.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

EstateReportingAPI/Bootstrapper/MiddlewareRegistry.cs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.OpenApi;
2+
using OpenIddict.Client;
23
using Shared.Middleware;
34

45
namespace EstateReportingAPI.Bootstrapper{
@@ -80,29 +81,24 @@ private void ConfigureSwagger(){
8081
private void ConfigureAuthentication(){
8182
String? inTestMode = Environment.GetEnvironmentVariable("InTestMode");
8283
if (String.Compare(inTestMode, Boolean.TrueString, StringComparison.InvariantCultureIgnoreCase) != 0){
83-
this.AddAuthentication(options => {
84-
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
85-
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
86-
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
87-
}).AddJwtBearer(options => {
88-
options.BackchannelHttpHandler = new HttpClientHandler{
89-
ServerCertificateCustomValidationCallback = (message,
90-
certificate,
91-
chain,
92-
sslPolicyErrors) => true
93-
};
94-
options.Authority = ConfigurationReader.GetValue("SecurityConfiguration", "Authority");
95-
options.Audience = ConfigurationReader.GetValue("SecurityConfiguration", "ApiName");
96-
97-
options.TokenValidationParameters = new TokenValidationParameters{
98-
ValidateAudience = false,
99-
ValidAudience =
100-
ConfigurationReader.GetValue("SecurityConfiguration", "ApiName"),
101-
ValidIssuer =
102-
ConfigurationReader.GetValue("SecurityConfiguration", "Authority"),
103-
};
104-
options.IncludeErrorDetails = true;
105-
});
84+
this.AddOpenIddict()
85+
// Register the OpenIddict client components.
86+
.AddClient(options => {
87+
// Allow grant_type=client_credentials to be negotiated.
88+
options.AllowClientCredentialsFlow();
89+
90+
// Disable token storage, which is not necessary for non-interactive flows like
91+
// grant_type=password, grant_type=client_credentials or grant_type=refresh_token.
92+
options.DisableTokenStorage();
93+
94+
// Register the System.Net.Http integration and use the identity of the current
95+
// assembly as a more specific user agent, which can be useful when dealing with
96+
// providers that use the user agent as a way to throttle requests (e.g Reddit).
97+
options.UseSystemNetHttp().SetProductInformation(typeof(Program).Assembly);
98+
99+
// Add a client registration matching the client application definition in the server project.
100+
options.AddRegistration(new OpenIddictClientRegistration { Issuer = new Uri(ConfigurationReader.GetValue("SecurityConfiguration", "Authority"), UriKind.Absolute), ClientId = ConfigurationReader.GetValue("SecurityConfiguration", "ApiName") });
101+
});
106102
}
107103
}
108104

EstateReportingAPI/EstateReportingAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21+
<PackageReference Include="OpenIddict.Client.SystemNetHttp" Version="7.4.0" />
2122
<PackageReference Include="Lamar" Version="15.0.1" />
2223
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="15.0.1" />
2324
<PackageReference Include="NLog.Extensions.Logging" Version="6.1.2" />

0 commit comments

Comments
 (0)