Skip to content

Commit 7b2a220

Browse files
authored
Merge pull request #217 from Resgrid/develop
CU-868ba84kp Added missing Public call, fixing OIDC postgres db issue.
2 parents 69a8373 + 6a8e793 commit 7b2a220

File tree

8 files changed

+1620
-1447
lines changed

8 files changed

+1620
-1447
lines changed

Providers/Resgrid.Providers.MigrationsPg/Sql/EF0001_PopulateOIDCDb.sql

Lines changed: 216 additions & 243 deletions
Large diffs are not rendered by default.

Web/Resgrid.Web.Services/Models/AuthorizationDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
33
using Microsoft.EntityFrameworkCore;
44

5+
56
namespace Resgrid.Web.Services.Models
67
{
78
public class ApplicationUser : IdentityUser { }

Web/Resgrid.Web.Services/Resgrid.Web.Services.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
</ItemGroup>
4040
<ItemGroup>
4141
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
42+
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
4243
<PackageReference Include="GeoJSON.Net" Version="1.4.1" />
4344
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
4445
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
@@ -48,6 +49,7 @@
4849
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
4950
<PackageReference Include="Autofac.Extras.CommonServiceLocator" Version="6.1.0" />
5051
<PackageReference Include="BundlerMinifier.Core" Version="3.2.449" />
52+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
5153
<PackageReference Include="OpenIddict" Version="6.1.1" />
5254
<PackageReference Include="OpenIddict.Core" Version="6.1.1" />
5355
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="6.1.1" />

Web/Resgrid.Web.Services/Startup.cs

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Autofac;
34
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Hosting;
@@ -69,8 +70,8 @@ namespace Resgrid.Web.ServicesCore
6970
{
7071
public class Startup
7172
{
72-
//public IConfiguration Configuration { get; }
73-
public IConfigurationRoot Configuration { get; private set; }
73+
//public IConfiguration Configuration { get; }
74+
public IConfigurationRoot Configuration { get; private set; }
7475
public ILifetimeScope AutofacContainer { get; private set; }
7576
public AutofacServiceLocator Locator { get; private set; }
7677
public IServiceCollection Services { get; private set; }
@@ -233,7 +234,7 @@ public void ConfigureServices(IServiceCollection services)
233234
Title = "Resgrid API",
234235
Version = "v4",
235236
Description = "The Resgrid Computer Aided Dispatch (CAD) API reference. Documentation: https://resgrid-core.readthedocs.io/en/latest/api/index.html",
236-
Contact = new OpenApiContact() {Email = "[email protected]", Name = "Resgrid Team", Url = new Uri("https://resgrid.com")},
237+
Contact = new OpenApiContact() { Email = "[email protected]", Name = "Resgrid Team", Url = new Uri("https://resgrid.com") },
237238
TermsOfService = new Uri("https://resgrid.com/Public/Terms")
238239
}
239240
);
@@ -246,7 +247,8 @@ public void ConfigureServices(IServiceCollection services)
246247
services.AddSignalR(hubOptions =>
247248
{
248249
hubOptions.EnableDetailedErrors = true;
249-
}).AddStackExchangeRedis(CacheConfig.RedisConnectionString, options => {
250+
}).AddStackExchangeRedis(CacheConfig.RedisConnectionString, options =>
251+
{
250252
options.Configuration.ChannelPrefix = $"{Config.SystemBehaviorConfig.GetEnvPrefix()}resgrid-evt-sr";
251253
});
252254

@@ -397,17 +399,6 @@ public void ConfigureServices(IServiceCollection services)
397399

398400
StripeConfiguration.ApiKey = Config.PaymentProviderConfig.IsTestMode ? PaymentProviderConfig.TestApiKey : PaymentProviderConfig.ProductionApiKey;
399401

400-
services.AddDbContext<AuthorizationDbContext>(options =>
401-
{
402-
// Configure the context to use Microsoft SQL Server.
403-
options.UseSqlServer(OidcConfig.ConnectionString);
404-
405-
// Register the entity sets needed by OpenIddict.
406-
// Note: use the generic overload if you need
407-
// to replace the default OpenIddict entities.
408-
options.UseOpenIddict<Guid>();
409-
});
410-
411402
// Register the Identity services.
412403
//services.AddIdentity<ApplicationUser, IdentityRole>()
413404
// .AddEntityFrameworkStores<ApplicationDbContext>()
@@ -435,15 +426,51 @@ public void ConfigureServices(IServiceCollection services)
435426
//// Register the Quartz.NET service and configure it to block shutdown until jobs are complete.
436427
//services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true);
437428

429+
if (OidcConfig.DatabaseType == DatabaseTypes.Postgres)
430+
{
431+
services.AddDbContext<AuthorizationDbContext>(options =>
432+
{
433+
// Configure the context to use Microsoft SQL Server.
434+
options.UseNpgsql(
435+
Config.OidcConfig.ConnectionString,
436+
opt =>
437+
{
438+
opt.EnableRetryOnFailure(
439+
maxRetryCount: 10,
440+
maxRetryDelay: TimeSpan.FromSeconds(30),
441+
errorCodesToAdd: new List<string>() { });
442+
443+
opt.UseAdminDatabase("postgres");
444+
});//.UseLowerCaseNamingConvention();
445+
446+
options.UseOpenIddict<Guid>();
447+
});
448+
449+
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
450+
}
451+
else
452+
{
453+
services.AddDbContext<AuthorizationDbContext>(options =>
454+
{
455+
// Configure the context to use Microsoft SQL Server.
456+
options.UseSqlServer(OidcConfig.ConnectionString);
457+
458+
// Register the entity sets needed by OpenIddict.
459+
// Note: use the generic overload if you need
460+
// to replace the default OpenIddict entities.
461+
options.UseOpenIddict<Guid>();
462+
});
463+
}
464+
438465
services.AddOpenIddict()
439466
// Register the OpenIddict core components.
440467
.AddCore(options =>
441468
{
442469
// Configure OpenIddict to use the Entity Framework Core stores and models.
443470
// Note: call ReplaceDefaultEntities() to replace the default OpenIddict entities.
444471
options.UseEntityFrameworkCore()
445-
.UseDbContext<AuthorizationDbContext>()
446-
.ReplaceDefaultEntities<Guid>();
472+
.UseDbContext<AuthorizationDbContext>()
473+
.ReplaceDefaultEntities<Guid>();
447474

448475
// Enable Quartz.NET integration.
449476
//options.UseQuartz();
@@ -469,7 +496,7 @@ public void ConfigureServices(IServiceCollection services)
469496
//options.AllowPasswordFlow()
470497
// .AllowRefreshTokenFlow();
471498
options//.AllowAuthorizationCodeFlow()
472-
//.AllowHybridFlow()
499+
//.AllowHybridFlow()
473500
.AllowClientCredentialsFlow()
474501
.AllowPasswordFlow()
475502
.AllowRefreshTokenFlow();
@@ -615,7 +642,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
615642
this.Locator = new AutofacServiceLocator(this.AutofacContainer);
616643
ServiceLocator.SetLocatorProvider(() => this.Locator);
617644

618-
app.Use(async (context, next) => {
645+
app.Use(async (context, next) =>
646+
{
619647
context.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000");
620648
context.Request.Scheme = "https";
621649
await next.Invoke();

0 commit comments

Comments
 (0)