ASP.NET(core)身份框架的替代方案是什么?
创始人
2024-09-20 00:00:28
0

有许多开源的身份管理框架可以用于 ASP.NET Core 项目,例如 IdentityServer、OpenIddict、SimpleAuthentication 等。以下是一些示例代码:

IdentityServer:

首先,安装 IdentityServer4 NuGet 包:

Install-Package IdentityServer4

然后,添加配置:

public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()); }

SimpleAuthentication:

首先,安装 SimpleAuthentication NuGet 包:

Install-Package SimpleAuthentication.Core

然后,使用以下代码配置 Google 身份验证:

services.AddSimpleAuthentication(options => { options.AuthenticateScheme = GoogleAuthenticationDefaults.AuthenticationScheme; options.AuthenticationSchemeDisplayName = "Google"; options.ClientId = Configuration["Authentication:Google:ClientId"]; options.ClientSecret = Configuration["Authentication:Google:ClientSecret"]; options.Fields.Add("hd"); }).AddGoogle();

OpenIddict:

首先,安装 OpenIddict NuGet 包:

Install-Package OpenIddict.EntityFrameworkCore

然后,添加以下代码到 Startup.cs 文件:

services.AddDbContext(options => { options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); options.UseOpenIddict(); });

services.AddOpenIddict() .AddCore(options => { options.UseEntityFrameworkCore() .UseDbContext(); }) .AddServer(options => { options.SetAccessTokenLifetime(TimeSpan.FromMinutes(30)) .SetRefreshTokenLifetime(TimeSpan.FromDays(7)) .AllowClientCredentialsFlow() .AllowAuthorizationCodeFlow() .AllowImplicitFlow() .DisableHttpsRequirement() .AddSigningKey(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Authentication:JwtBearer:SecurityKey"]))); }) .AddValidation();

相关内容

热门资讯

第三方技巧"兴动互娱... 第三方技巧"兴动互娱脚本"真是真的有辅助app(哔哩哔哩)1、下载好兴动互娱脚本正确养号方法之后点击...
来临"广东雀神智能辅... 来临"广东雀神智能辅助照片"切实是有辅助挂(哔哩哔哩)1、玩家可以在广东雀神智能辅助照片透视最简单三...
透视新版"九九山城万... 透视新版"九九山城万州辅助"果然确实有辅助工具(哔哩哔哩)1、九九山城万州辅助破解器简单,九九山城万...
日前"新道游辅助器&... 日前"新道游辅助器"好像真的有辅助神器(哔哩哔哩)1、新道游辅助器脚本辅助下载、新道游辅助器免费透视...
为切实保障"边锋干瞪... 为切实保障"边锋干瞪眼房租胡"好像确实有辅助攻略(哔哩哔哩)1、边锋干瞪眼房租胡模拟器是什么优化,边...
2026版复盘"新海... 2026版复盘"新海贝之城开挂"确实存在有辅助工具(哔哩哔哩)暗藏猫腻,小编详细说明新海贝之城开挂破...
方法辅助挂"传送屋有... 方法辅助挂"传送屋有没有挂"本来是有辅助app(哔哩哔哩)1、传送屋有没有挂有没有辅助教程、传送屋有...
攻略辅助挂"佛手十三... 攻略辅助挂"佛手十三道破解版安卓"真是确实有辅助插件(哔哩哔哩)该软件可以轻松地帮助玩家将佛手十三道...
透视有挂"四川血战到... 透视有挂"四川血战到底攻略"切实真的有辅助神器(哔哩哔哩)1、任何四川血战到底攻略透视是真的假的的玩...
今天下午"天蝎辅助&... 今天下午"天蝎辅助"原来真的是有辅助挂(哔哩哔哩)运天蝎辅助辅助工具,进入游戏界面。进入天蝎辅助辅助...