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

相关内容

热门资讯

热点推荐"手机游戏挂... 热点推荐"手机游戏挂机辅助软件"开挂(神器)辅助神器有挂攻略-可靠教程 >>您好:软件加薇13670...
必备教程"微信卡五星... 您好:这款微信卡五星辅助器游戏是可以开挂的,确实是有挂的,很多玩家在这款微信卡五星辅助器游戏中打牌都...
一分钟揭秘"下载微乐... 一分钟揭秘"下载微乐小程序自建房透视"开挂(神器)辅助神器新版有挂-微扑克教程1、下载安装好下载微乐...
重要通知"衡阳丫丫字... 重要通知"衡阳丫丫字牌靠谱吗"开挂(安装)辅助安装有挂分享-黑科技教程;无需打开直接搜索薇:1367...
传递经验"pokem... 传递经验"pokemmo脚本辅助下载"开挂(平台)辅助平台了解有挂-玩家教程《详细加薇1367043...
推荐十款"掌中乐游戏... 推荐十款"掌中乐游戏辅助器"开挂(下载)辅助下载有挂教程-辅助教程;无需打开直接搜索加薇136704...
透视透视"决战卡五星... 透视透视"决战卡五星看牌器"开挂(下载)辅助下载有挂解惑-透视教程>>您好:软件加薇13670430...
实测必看"传送屋激k... 实测必看"传送屋激k万能辅助器app"开挂(安装)辅助安装有挂总结-AI教程 【无需打开直接搜索加薇...
教程攻略"新圣游脚本... 新圣游脚本下载是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可以加我微信...
科技分享"钱塘十水三... 您好:钱塘十水三挂件这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特...