Skip to content

Commit

Permalink
Version 9.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JonPSmith committed Nov 30, 2024
1 parent c03c8bd commit 5279c04
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 63 deletions.
1 change: 1 addition & 0 deletions AuthPermissions.AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ReleaseNotes.md = ReleaseNotes.md
UpdateToVersion6.md = UpdateToVersion6.md
UpdateToVersion620.md = UpdateToVersion620.md
UpdateToVersion9.md = UpdateToVersion9.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example2.WebApiWithToken.IndividualAccounts", "Example2.WebApiWithToken.IndividualAccounts\Example2.WebApiWithToken.IndividualAccounts.csproj", "{E2667176-A75B-4182-94AF-43D8F0CF989A}"
Expand Down
82 changes: 41 additions & 41 deletions AuthPermissions.AspNetCore/CreateNuGetRelease.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,66 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>AuthPermissions.AspNetCore</id>
<version>8.1.0</version>
<version>9.0.0</version>
<authors>Jon P Smith</authors>
<product>AuthPermissions.AspNetCore</product>
<copyright>Copyright (c) 2021 Jon P Smith</copyright>
<description>Provides extra authorization and multi-tenant features to an ASP.NET Core application.</description>
<releaseNotes>
- Code to recreate the ShardingEntries if the FileStore Cache is deleted - see issue #115
- Updates vulnerable NuGets Microsoft.Identity.Client and System.Text.Json
- Updated to .NET 9 version
- BREAKING CHANGE: EF Core 9 added extra migration checks - see UpdateToVersion9.md to update your multi-tenant DbContext.
</releaseNotes>
<license type="expression">MIT</license>
<projectUrl>https://github.com/JonPSmith/AuthPermissions.AspNetCore</projectUrl>
<icon>images\AuthPermissionsAspNetCoreNuGetIcon.png</icon>
<tags>ASP.NET Core, Entity Framework Core</tags>
<dependencies>
<group targetFramework="net8.0">
<group targetFramework="net9.0">
<dependency id="GenericServices.StatusGeneric" version="1.2.0" />
<dependency id="Microsoft.AspNetCore.Identity.EntityFrameworkCore" version="8.0.0" />
<dependency id="Microsoft.Data.Sqlite.Core" version="8.0.2" />
<dependency id="Microsoft.EntityFrameworkCore" version="8.0.2" />
<dependency id="Microsoft.EntityFrameworkCore.InMemory" version="8.0.2" />
<dependency id="Microsoft.EntityFrameworkCore.Sqlite" version="8.0.2" />
<dependency id="Microsoft.EntityFrameworkCore.SqlServer" version="8.0.2" />
<dependency id="Npgsql.EntityFrameworkCore.PostgreSQL" version="8.0.2" />
<dependency id="Microsoft.EntityFrameworkCore.Tools" version="8.0.2" />
<dependency id="Microsoft.Extensions.Hosting" version="8.0.0" />
<dependency id="Microsoft.AspNetCore.Identity.EntityFrameworkCore" version="9.0.0" />
<dependency id="Microsoft.Data.Sqlite.Core" version="9.0.0" />
<dependency id="Microsoft.EntityFrameworkCore" version="9.0.0" />
<dependency id="Microsoft.EntityFrameworkCore.InMemory" version="9.0.0" />
<dependency id="Microsoft.EntityFrameworkCore.Sqlite" version="9.0.0" />
<dependency id="Microsoft.EntityFrameworkCore.SqlServer" version="9.0.0" />
<dependency id="Npgsql.EntityFrameworkCore.PostgreSQL" version="9.0.1" />
<dependency id="Microsoft.EntityFrameworkCore.Tools" version="9.0.0" />
<dependency id="Microsoft.Extensions.Hosting" version="9.0.0" />
<dependency id="Net.RunMethodsSequentially" version="2.0.1" />
<dependency id="Net.LocalizeMessagesAndErrors" version="8.0.0" />
<dependency id="Microsoft.AspNetCore.Authentication.OpenIdConnect" version="8.0.0" />
<dependency id="Microsoft.AspNetCore.Authorization" version="8.0.0" />
<dependency id="Microsoft.IdentityModel.JsonWebTokens" version="7.5.1" />
<dependency id="Net.LocalizeMessagesAndErrors" version="9.0.0" />
<dependency id="Microsoft.AspNetCore.Authentication.OpenIdConnect" version="9.0.0" />
<dependency id="Microsoft.AspNetCore.Authorization" version="9.0.0" />
<dependency id="Microsoft.IdentityModel.JsonWebTokens" version="8.2.1" />
<dependency id="Net.DistributedFileStoreCache" version="2.0.0" />
<dependency id="System.IdentityModel.Tokens.Jwt" version="7.1.2" />
<dependency id="EntityFrameworkCore.Exceptions.PostgreSQL" version="8.1.2" />
<dependency id="EntityFrameworkCore.Exceptions.Sqlite" version="8.1.2" />
<dependency id="EntityFrameworkCore.Exceptions.SqlServer" version="8.0.0.2" />
<dependency id="Microsoft.EntityFrameworkCore.Design" version="8.0.2" />
<dependency id="Microsoft.Extensions.Localization.Abstractions" version="8.0.0" />
<dependency id="DistributedLock" version="2.4.0" />
<dependency id="System.IdentityModel.Tokens.Jwt" version="8.2.1" />
<dependency id="EntityFrameworkCore.Exceptions.PostgreSQL" version="8.1.3" />
<dependency id="EntityFrameworkCore.Exceptions.Sqlite" version="8.1.3" />
<dependency id="EntityFrameworkCore.Exceptions.SqlServer" version="8.1.3" />
<dependency id="Microsoft.EntityFrameworkCore.Design" version="9.0.0" />
<dependency id="Microsoft.Extensions.Localization.Abstractions" version="9.0.0" />
<dependency id="DistributedLock" version="2.5.0" />
<dependency id="Microsoft.Graph" version="4.54.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\AuthPermissions\bin\Release\net8.0\AuthPermissions.dll" target="lib\net8.0" />
<file src="..\AuthPermissions\bin\Release\net8.0\AuthPermissions.xml" target="lib\net8.0" />
<file src="..\AuthPermissions\bin\Release\net8.0\AuthPermissions.pdb" target="lib\net8.0" />
<file src="..\AuthPermissions.AspNetCore\bin\Release\net8.0\AuthPermissions.AspNetCore.dll" target="lib\net8.0" />
<file src="..\AuthPermissions.AspNetCore\bin\Release\net8.0\AuthPermissions.AspNetCore.xml" target="lib\net8.0" />
<file src="..\AuthPermissions.AspNetCore\bin\Release\net8.0\AuthPermissions.AspNetCore.pdb" target="lib\net8.0" />
<file src="..\AuthPermissions.BaseCode\bin\Release\net8.0\AuthPermissions.BaseCode.dll" target="lib\net8.0" />
<file src="..\AuthPermissions.BaseCode\bin\Release\net8.0\AuthPermissions.BaseCode.xml" target="lib\net8.0" />
<file src="..\AuthPermissions.BaseCode\bin\Release\net8.0\AuthPermissions.BaseCode.pdb" target="lib\net8.0" />
<file src="..\AuthPermissions.PostgreSql\bin\Release\net8.0\AuthPermissions.PostgreSql.dll" target="lib\net8.0" />
<file src="..\AuthPermissions.PostgreSql\bin\Release\net8.0\AuthPermissions.PostgreSql.xml" target="lib\net8.0" />
<file src="..\AuthPermissions.PostgreSql\bin\Release\net8.0\AuthPermissions.PostgreSql.pdb" target="lib\net8.0" />
<file src="..\AuthPermissions.SqlServer\bin\Release\net8.0\AuthPermissions.SqlServer.dll" target="lib\net8.0" />
<file src="..\AuthPermissions.SqlServer\bin\Release\net8.0\AuthPermissions.SqlServer.pdb" target="lib\net8.0" />
<file src="..\AuthPermissions.SupportCode\bin\Release\net8.0\AuthPermissions.SupportCode.dll" target="lib\net8.0" />
<file src="..\AuthPermissions.SupportCode\bin\Release\net8.0\AuthPermissions.SupportCode.xml" target="lib\net8.0" />
<file src="..\AuthPermissions.SupportCode\bin\Release\net8.0\AuthPermissions.SupportCode.pdb" target="lib\net8.0" />
<file src="..\AuthPermissions\bin\Release\net9.0\AuthPermissions.dll" target="lib\net9.0" />
<file src="..\AuthPermissions\bin\Release\net9.0\AuthPermissions.xml" target="lib\net9.0" />
<file src="..\AuthPermissions\bin\Release\net9.0\AuthPermissions.pdb" target="lib\net9.0" />
<file src="..\AuthPermissions.AspNetCore\bin\Release\net9.0\AuthPermissions.AspNetCore.dll" target="lib\net9.0" />
<file src="..\AuthPermissions.AspNetCore\bin\Release\net9.0\AuthPermissions.AspNetCore.xml" target="lib\net9.0" />
<file src="..\AuthPermissions.AspNetCore\bin\Release\net9.0\AuthPermissions.AspNetCore.pdb" target="lib\net9.0" />
<file src="..\AuthPermissions.BaseCode\bin\Release\net9.0\AuthPermissions.BaseCode.dll" target="lib\net9.0" />
<file src="..\AuthPermissions.BaseCode\bin\Release\net9.0\AuthPermissions.BaseCode.xml" target="lib\net9.0" />
<file src="..\AuthPermissions.BaseCode\bin\Release\net9.0\AuthPermissions.BaseCode.pdb" target="lib\net9.0" />
<file src="..\AuthPermissions.PostgreSql\bin\Release\net9.0\AuthPermissions.PostgreSql.dll" target="lib\net9.0" />
<file src="..\AuthPermissions.PostgreSql\bin\Release\net9.0\AuthPermissions.PostgreSql.xml" target="lib\net9.0" />
<file src="..\AuthPermissions.PostgreSql\bin\Release\net9.0\AuthPermissions.PostgreSql.pdb" target="lib\net9.0" />
<file src="..\AuthPermissions.SqlServer\bin\Release\net9.0\AuthPermissions.SqlServer.dll" target="lib\net9.0" />
<file src="..\AuthPermissions.SqlServer\bin\Release\net9.0\AuthPermissions.SqlServer.pdb" target="lib\net9.0" />
<file src="..\AuthPermissions.SupportCode\bin\Release\net9.0\AuthPermissions.SupportCode.dll" target="lib\net9.0" />
<file src="..\AuthPermissions.SupportCode\bin\Release\net9.0\AuthPermissions.SupportCode.xml" target="lib\net9.0" />
<file src="..\AuthPermissions.SupportCode\bin\Release\net9.0\AuthPermissions.SupportCode.pdb" target="lib\net9.0" />
<file src="..\AuthPermissions.AspNetCore\images\AuthPermissionsAspNetCoreNuGetIcon.png" target="images\" />
</files>
</package>
3 changes: 2 additions & 1 deletion AuthPermissions.AspNetCore/MultiProjPack.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<copyright>Copyright (c) 2021 Jon P Smith</copyright>
<description>Provides extra authorization and multi-tenant features to an ASP.NET Core application.</description>
<releaseNotes>
- .NET 9 version
- Updated to .NET 9 version
- BREAKING CHANGE: EF Core 9 added extra migration checks - see UpdateToVersion9.md to update your multi-tenant DbContext.
</releaseNotes>
<license type="expression">MIT</license>
<projectUrl>https://github.com/JonPSmith/AuthPermissions.AspNetCore</projectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ public AuthPermissionsDbContext(DbContextOptions<AuthPermissionsDbContext> optio
_customConfiguration = customConfiguration;
}

/// <summary>
/// This is needed for EF Core 9 and above when building a multi-tenant application.
/// This allows you to add more than one migration on this database
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
//This allows you to add more that one migration on this database
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder);
}
Expand Down
9 changes: 7 additions & 2 deletions Example3.InvoiceCode/EfCoreCode/InvoicesDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ public InvoicesDbContext(DbContextOptions<InvoicesDbContext> options, IGetDataKe
: base(options)
{
// The DataKey is null when: no one is logged in, its a background service, or user hasn't got an assigned tenant
// In these cases its best to set the data key that doesn't match any possible DataKey
// In these cases it's best to set the data key that doesn't match any possible DataKey
DataKey = dataKeyFilter?.DataKey ?? "Bad key";
}

/// <summary>
/// This is needed for EF Core 9 and above when building a multi-tenant application.
/// This allows you to add more than one migration on this database
/// NOTE: You don't need to add this code if you are building a Sharding-Only type multi-tenant.
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
//This allows you to add more that one migration on this database
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder);
}
Expand Down
30 changes: 17 additions & 13 deletions Example3.MvcWebApp.IndividualAccounts/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;

namespace Example3.MvcWebApp.IndividualAccounts.Data
namespace Example3.MvcWebApp.IndividualAccounts.Data;

public class ApplicationDbContext : IdentityDbContext
{
public class ApplicationDbContext : IdentityDbContext
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) {}

/// <summary>
/// This is needed for EF Core 9 and above when building a multi-tenant application.
/// This allows you to add more than one migration on this database
/// NOTE: You don't need to add this code if you are building a Sharding-Only type multi-tenant.
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) {}

protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
//This allows you to add more that one migration on this database
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder);
}
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ public ShardingSingleDbContext(DbContextOptions<ShardingSingleDbContext> options
Database.SetConnectionString(shardingDataKeyAndConnect.ConnectionString);
}

/// <summary>
/// This is needed for EF Core 9 and above when building a multi-tenant application.
/// This allows you to add more than one migration on this database
/// NOTE: You don't need to add this code if you are building a Sharding-Only type multi-tenant.
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
//This allows you to add more that one migration on this database
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder);
}
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ The AuthP is an open-source library under the MIT licence (and remain as a open-

## List of versions and which .NET framework they support

- Version 9.?.? supports NET 9 only (simpler to update to next NET release)
- Version 8.?.? supports NET 8 only (simpler to update to next NET release)
- Version 6.?.? supports NET 6, 7 and 8
- Version 5.?.? supports NET 6 and 7

If you have already built your application using an older version, then you need to look at the following "how up update" documents

- For AuthPermissions.AspNetCore versions below 9 see [UpdateToVersion9.md](https://github.com/JonPSmith/AuthPermissions.AspNetCore/blob/main/UpdateToVersion9.md)
- From Migrating from AuthPermissions.AspNetCore 3, 4, 5 to 6.1 see [UpdateToVersion620.md](https://github.com/JonPSmith/AuthPermissions.AspNetCore/blob/main/UpdateToVersion620.md). NOTE: you only need to do this if you are using the "Sign up for a new tenant, with versioning" (shortened to "Sign up Tenant") feature **AND** your multi-tenant uses [sharding](https://github.com/JonPSmith/AuthPermissions.AspNetCore/wiki/Sharding-explained).
- From Migrating from AuthPermissions.AspNetCore 3, 4, 5 to 6.0 see [UpdateToVersion6.md](https://github.com/JonPSmith/AuthPermissions.AspNetCore/blob/main/UpdateToVersion5.md)
- From Migrating from AuthPermissions.AspNetCore 2, 3 or 4.* to 5.0 see [UpdateToVersion5.md](https://github.com/JonPSmith/AuthPermissions.AspNetCore/blob/main/UpdateToVersion5.md)
- From Migrating from AuthPermissions.AspNetCore 2.* to 3.0 see [UpdateToVersion3.md](https://github.com/JonPSmith/AuthPermissions.AspNetCore/blob/main/UpdateToVersion3.md)
- From Migrating from AuthPermissions.AspNetCore 1.* to 1.0 see [UpdateToVersion2.md](https://github.com/JonPSmith/AuthPermissions.AspNetCore/blob/main/UpdateToVersion2.md)

The AuthP library also:

Expand Down
7 changes: 6 additions & 1 deletion Test/DiTestHelpers/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ public class ApplicationDbContext : IdentityDbContext
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) { }

/// <summary>
/// This is needed for EF Core 9 and above when building a multi-tenant application.
/// This allows you to add more than one migration on this database
/// NOTE: You don't need to add this code if you are building a Sharding-Only type multi-tenant.
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
//This allows you to add more that one migration on this database
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder);
}
Expand Down
39 changes: 39 additions & 0 deletions UpdateToVersion9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Updating your code from AuthPermissions.AspNetCore to EF Core 9

EF Core 9 has added code to ensure that migrations are executed correctly - see EF Core 9's [updated migrations](https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-9.0/whatsnew#migrations). The AuthP library already have code to ensure that migrations are executed correctly, but one of the EF Core 9's changes is to check that only one migration is executed on a database. It does this to ensure that migrations don't clash.

AuthP does apply two migrations when building multi-tenant applications. This means you need to add a `OnConfiguring` the code shown to your tenant's `DbContext`. The code below comes from [Example3's tenant `DbContext`](https://github.com/JonPSmith/AuthPermissions.AspNetCore/blob/main/Example3.InvoiceCode/EfCoreCode/InvoicesDbContext.cs) - the new code for EF Core 9 is the new `OnConfiguring` method. See below.

```c#
namespace Example3.MvcWebApp.IndividualAccounts.Data;

public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) {}

/// <summary>
/// This is needed for EF Core 9 and above when building a multi-tenant application.
/// This allows you to add more than one migration on this database
/// NOTE: You don't need to add this code if you are building a Sharding-Only type multi-tenant.
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.ConfigureWarnings(x =>
x.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder);
}

//other code left out...
}
```

NOTE: If you get an `InvalidOperationException` with the text shown below on startup, then you haven't added the `OnConfiguring` shown above, then you haven't added the code above.

```text
An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context '-your tenant context-' has pending changes. Add a new migration before updating the database. This exception can be suppressed or logged by passing event ID 'RelationalEventId.PendingModelChangesWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
```

END

0 comments on commit 5279c04

Please sign in to comment.