DuendeSoftware / Support

Support for Duende Software products
20 stars 0 forks source link

Upgrading .Net 7 to 8 / Duende v6 to 7 - Migration is erroring. #1351

Closed briantheitguy closed 1 month ago

briantheitguy commented 1 month ago

Which version of Duende IdentityServer are you using? 7.0.5

Which version of .NET are you using? v8

Describe the bug Following the upgrade steps on the duende site to upgrade to v7, I am hitting errors while running the migration steps.

Error: Method 'get_ServerSideSessions' in type 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext`1' from assembly 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.

To Reproduce Upgrade a project from .Net 7 to 8 & Duende v6.03 to 7.05. Steps here: https://docs.duendesoftware.com/identityserver/v7/upgrades/v6.3_to_v7.0

Running the following...

dotnet ef migrations add Update_DuendeIdentityServer_v7_0 -c ConfigurationDbContext -o Migrations/ConfigurationDb

Expected behavior I am expecting it to add the needed db table/column changes for the new version.

Log output/exception with stacktrace

PM> dotnet ef migrations add Update_DuendeIdentityServer_v7_0 -c ConfigurationDbContext -o Data/Migrations
Build started...
Build succeeded.
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Method 'get_ServerSideSessions' in type 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext`1' from assembly 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
The exception 'Method 'get_ServerSideSessions' in type 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext`1' from assembly 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.' was thrown while attempting to find 'DbContext' types. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
briantheitguy commented 1 month ago

I implemented the changes listed in this commit: https://github.com/dotnet/aspnetcore/issues/46025#issuecomment-1379085253

I am now hitting new errors after it builds..

MissingMethodException: Method not found: 'System.String Duende.IdentityServer.Extensions.HttpContextExtensions.GetIdentityServerIssuerUri(Microsoft.AspNetCore.Http.HttpContext)'.
Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync(MessageReceivedContext messageReceivedContext)
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine stateMachine)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<TStateMachine>(ref TStateMachine stateMachine)
Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync(MessageReceivedContext messageReceivedContext)
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerEvents.MessageReceived(MessageReceivedContext context)
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.AuthenticateAsync()
Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, string scheme)
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.AuthenticateAsync()
Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, string scheme)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in DynamicSchemeAuthenticationMiddleware.cs
Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in BaseUrlMiddleware.cs
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Here are my packages in the server project:

  <ItemGroup>
    <PackageReference Include="Braintree" Version="5.26.0" />
    <PackageReference Include="CsvHelper" Version="33.0.1" />
    <PackageReference Include="Duende.IdentityServer" Version="7.0.5" />
    <PackageReference Include="Duende.IdentityServer.AspNetIdentity" Version="7.0.5" />
    <PackageReference Include="Duende.IdentityServer.EntityFramework" Version="7.0.5" />
    <PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Version="8.0.0-preview.6.23329.11" />
    <PackageReference Include="MudBlazor" Version="7.4.0" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.7" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.7" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.7" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.7" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.3" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  </ItemGroup>

And attached is a screenshot for my localhost. new1

paviad commented 1 month ago

Microsoft has removed support for API authorization with IdentityServer in .NET 8 and above.

I have extracted the deprecated library from the .NET source and adapted it to IdentityServer 7 at https://github.com/paviad/apiauthorization-identityserver

Feel free to use.