Search code examples
c#.net-coreopeniddict

OpenIddict problems


I just came back to a project after a long time away from it (possibly over a year) and after updating VS2017 to Version 15.7.5 I was met with a number of problems when I tried to rebuild the project. The first problem was that the nuget dependencies complained that for OpenIddict assemblies "1.0.0.-*" was requested but received "1.0.0-rtm-1063". These errors make no sense to me but I amended my .csproj file as shown below:

<!-- OpenIdDict -->
<!-- 1.0.0.-* changed to 1.0.0.-rtm-1063 -->
<PackageReference Include="AspNet.Security.OAuth.Validation" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" />
<PackageReference Include="OpenIddict" Version="1.0.0-rtm-1063" />
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="1.0.0-rtm-1063" />
<PackageReference Include="OpenIddict.Mvc" Version="1.0.0-rtm-1063" />

This is obviously not a good permanent solution (what is the proper solution?) plus this led to a series of other problems which were cured by replacing

using OpenIddict.Models;

with

using OpenIddict.EntityFrameworkCore.Models;

This left me with two problems to which I can't find a solution.

services.AddOpenIddict().AddEntityFrameworkCoreStores<ApplicationDbContext>()

is undefined.

The call in the Configure() Method to app.UseOpenIddict(); complains the UseOpenIddict is undefined.

If someone can point me in the right direction for these problems, I would be very grateful.

Additionally, this project is using .NET Core 1.1 which I understand has been superseded by .NET Core 2.1. It's not clear to me how I upgrade the project to use .NET Core 2.1. The drop down in the VS2017 GUI contains only 1.0 and 1.1 and "Install Other Frameworks..." But even after installing the latest 2.1 SDK and Runtime, there is still no option in the dropdown for .NET Core 2.1. What am I doing wrong?


Solution

  • You should remove <PackageReference Include="AspNet.Security.OAuth.Validation" Version="1.0.0" /> as it's now transitively referenced by the OpenIddict metapackage.

    In RC3, the syntax has changed a bit so services.AddOpenIddict().AddEntityFrameworkCoreStores<ApplicationDbContext>() is now longer valid:

    // In OpenIddict RC2, all the options used to be grouped.
    services.AddOpenIddict(options =>
    {
        options.AddEntityFrameworkCoreStores<ApplicationDbContext>();
    
        options.AddMvcBinders();
    
        options.EnableAuthorizationEndpoint("/connect/authorize")
               .EnableLogoutEndpoint("/connect/logout")
               .EnableTokenEndpoint("/connect/token")
               .EnableUserinfoEndpoint("/api/userinfo");
    
        options.AllowAuthorizationCodeFlow()
               .AllowPasswordFlow()
               .AllowRefreshTokenFlow();
    
        options.RegisterScopes(OpenIdConnectConstants.Scopes.Email,
                               OpenIdConnectConstants.Scopes.Profile,
                               OpenIddictConstants.Scopes.Roles);
    
        options.RequireClientIdentification();
    
        options.EnableRequestCaching();
    
        options.EnableScopeValidation();
    
        options.DisableHttpsRequirement();
    });
    
    // In OpenIddict RC3, the options are now split into 3 categories:
    // the core services, the server services and the validation services.
    services.AddOpenIddict()
        .AddCore(options =>
        {
            // AddEntityFrameworkCoreStores() is now UseEntityFrameworkCore().
            options.UseEntityFrameworkCore()
                   .UseDbContext<ApplicationDbContext>();
        })
    
        .AddServer(options =>
        {
            // AddMvcBinders() is now UseMvc().
            options.UseMvc();
    
            options.EnableAuthorizationEndpoint("/connect/authorize")
                   .EnableLogoutEndpoint("/connect/logout")
                   .EnableTokenEndpoint("/connect/token")
                   .EnableUserinfoEndpoint("/api/userinfo");
    
            options.AllowAuthorizationCodeFlow()
                   .AllowPasswordFlow()
                   .AllowRefreshTokenFlow();
    
            options.RegisterScopes(OpenIdConnectConstants.Scopes.Email,
                                   OpenIdConnectConstants.Scopes.Profile,
                                   OpenIddictConstants.Scopes.Roles);
    
            // This API was removed as client identification is now
            // required by default. You can remove or comment this line.
            //
            // options.RequireClientIdentification();
    
            options.EnableRequestCaching();
    
            // This API was removed as scope validation is now enforced
            // by default. You can safely remove or comment this line.
            //
            // options.EnableScopeValidation();
    
            options.DisableHttpsRequirement();
        });