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

相关内容

热门资讯

一分钟了解外挂!新棋联盟外挂多... 一分钟了解外挂!新棋联盟外挂多功能AI插件,新棋联盟切实真的有外挂插件一、新棋联盟游戏安装教程牌型概...
今日公布外挂!多多娱乐外挂多功... 今日公布外挂!多多娱乐外挂多功能AI技巧,多多娱乐切实有外挂技巧1、任何多多娱乐透视是真的假的的玩家...
实测分享透视挂!超稳新城透视挂... 实测分享透视挂!超稳新城透视挂多功能AI脚本,超稳新城果然真的有透视挂脚本1、点击下载安装,超稳新城...
玩家必看分享作弊器!闲玩娱乐鱼... 玩家必看分享作弊器!闲玩娱乐鱼虾蟹作弊器多功能AI方法,闲玩娱乐鱼虾蟹切实是真的有作弊器方法1、闲玩...
分享认知开挂!皇家互娱开挂多功... 分享认知开挂!皇家互娱开挂多功能AI教程,皇家互娱竟然是有开挂教程所有人都在同一条线上,像星星一样排...
玩家科普作弊器!新道游作弊器多... 玩家科普作弊器!新道游作弊器多功能AI技巧,新道游本来是真的有作弊器技巧1、进入游戏-大厅左侧-新手...
今日重大通报透视器!新九方透视... 您好,新九方这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游...
终于清楚辅助!四通娱乐3辅助多... 终于清楚辅助!四通娱乐3辅助多功能AIapp,四通娱乐3原来真的是有辅助app所有人都在同一条线上,...
科普分享外挂!闲时互娱外挂多功... 科普分享外挂!闲时互娱外挂多功能AI技巧,闲时互娱原来有外挂技巧1、闲时互娱辅助软件下载优化,闲时互...
玩家必看科普作弊器!魔龙作弊器... 玩家必看科普作弊器!魔龙作弊器多功能AI工具,魔龙一直真的是有作弊器工具1、让任何用户在无需魔龙安装...