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黑科技系统规...
原来有辅助!河洛杠次胜率辅助器... 原来有辅助!河洛杠次胜率辅助器,飞驰娱乐科技,玩家亲测开挂(确实有挂) 了解更多开挂安装加(1367...
曝光辅助!小二互娱辅助,福建天... 曝光辅助!小二互娱辅助,福建天天开心辅助器真的假的,一分钟了解开挂(有挂详细)《详细加薇136704...
详细辅助!小程序微乐辅助软件,... 详细辅助!小程序微乐辅助软件,决战卡五星辅助修改器,分享给玩家开挂(有挂解惑) 【无需打开直接搜索加...
通报辅助!新海贝之城脚本,同城... 通报辅助!新海贝之城脚本,同城游辅助软件,透视苹果版开挂(有挂教学)同城游辅助软件ai黑科技系统规律...
细节辅助!约局吧黑科技辅助器,... 长了四人上品十三攻略开挂教程视频分享装挂详细步骤在当今的网络游戏中,长了四人上品十三攻略作为一种经典...
盘点辅助!朋朋政和软件辅助,赣... 您好:这款赣牌圈小程序破解版游戏是可以开挂的,确实是有挂的,很多玩家在这款赣牌圈小程序破解版游戏中打...
科技辅助!指尖四川辅助脚本,乐... 科技辅助!指尖四川辅助脚本,乐平讨赏挂,分享个大家开挂(有挂助手) 了解更多开挂安装加(136704...
盘点辅助!麻雀智能辅助软件开挂... 盘点辅助!麻雀智能辅助软件开挂,新上游通用挂是真的吗,透视能赢开挂(有挂分析)您好:新上游通用挂是真...
教会辅助!人海大厅脚本,衢州都... 教会辅助!人海大厅脚本,衢州都莱辅助软件,教程辅助开挂(有挂辅助)>>您好:软件加薇13670430...