c# - net core 2.2 到 3.0 身份验证迁移 AddOpenIdConnect
问题描述
目前我正在将 asp net core 2.2 网站升级到使用 Identity Server 4 身份验证的 net core 3.0 并发现阻止我完成此任务的问题:在 .net core 3.0 中 OpenIdConnectExtensions 中没有AddOpenIdConnect方法(文档很清楚它:
那么.net core 3.0 有什么替代品吗?
在 net core 2.2 中工作的 Startup.cs
IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
})
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = "sso url";
options.RequireHttpsMetadata = false;
options.ClientId = "client_id";
options.ClientSecret = "secret";
options.ResponseType = $"{OpenIdConnectParameterNames.Code} {OpenIdConnectParameterNames.IdToken}";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
})
解决方案
如果您在此处查看 2.2 -> 3.0 迁移文档: https ://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio
您将在删除程序集的添加包引用部分中看到(https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio# add-package-references-for-removed-assemblies),现在有一个 nuget 包来支持这一点:
https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.OpenIdConnect
推荐阅读
- joomla - JInstaller: :Install: 找不到 XML 安装文件
- sql - 根据现有列选择逗号分隔的字符串
- python - Python 3 正则表达式提取字符串的一部分
- ios - 在 Xcode 中,如何在不复制出口引用的情况下复制 xib 文件
- big-o - 我们如何以最简单的方式用 Theta 和 Big Oh 表示法编写 nCr?
- arrays - 如何在未排序的数组中找到 n 个元素的最大值 n 次?每次后一个元素的值以线性方式减少 n
- oauth-2.0 - 如何在 IdentityServer4 中接受两种身份验证方案?
- c# - 组合框不正确地过滤 datagridview 数据
- ios - 如何将 swift 框架添加到 Objective-C 项目
- node.js - 如何使用节点 js 和套接字 io 对一个客户端发送到另一个客户端的消息进行端到端加密?