【问题标题】:OpenIddict problemsOpenIddict 问题
【发布时间】:2019-01-05 14:39:07
【问题描述】:

我在离开一个项目很长时间(可能超过一年)后才回到一个项目,并且在将 VS2017 更新到版本 15.7.5 后,我在尝试重建项目时遇到了许多问题。第一个问题是 nuget 依赖项抱怨 OpenIddict 程序集“1.0.0.-*”被请求但收到“1.0.0-rtm-1063”。这些错误对我来说毫无意义,但我修改了我的 .csproj 文件,如下所示:

<!-- 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" />

这显然不是一个好的永久解决方案(什么是正确的解决方案?)加上这导致了一系列其他问题,这些问题通过替换解决了

using OpenIddict.Models;

using OpenIddict.EntityFrameworkCore.Models;

这给我留下了两个我找不到解决方案的问题。

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

未定义。

在 Configure() 方法中调用 app.UseOpenIddict();抱怨 UseOpenIddict 未定义。

如果有人能为这些问题指出正确的方向,我将不胜感激。

此外,这个项目使用的是 .NET Core 1.1,据我了解,它已被 .NET Core 2.1 取代。我不清楚如何升级项目以使用 .NET Core 2.1。 VS2017 GUI 中的下拉菜单仅包含 1.0 和 1.1 以及“安装其他框架...”但即使安装了最新的 2.1 SDK 和运行时,.NET Core 2.1 的下拉菜单中仍然没有选项。我做错了什么?

【问题讨论】:

标签: c# .net-core openiddict


【解决方案1】:

您应该删除 &lt;PackageReference Include="AspNet.Security.OAuth.Validation" Version="1.0.0" /&gt;,因为它现在被 OpenIddict 元包传递引用。

在 RC3 中,语法发生了一些变化,因此 services.AddOpenIddict().AddEntityFrameworkCoreStores&lt;ApplicationDbContext&gt;() 现在不再有效:

// 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();
    });

【讨论】:

  • 非常感谢您的意见。自从我上次看到它以来,一切都发生了很大变化。
猜你喜欢
  • 2021-11-20
  • 1970-01-01
  • 2022-01-11
  • 2021-07-25
  • 2022-06-16
  • 2017-06-15
  • 2018-03-24
  • 2019-06-17
  • 2017-09-17
相关资源
最近更新 更多