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

相关内容

热门资讯

透视计算!wpk辅助器安装,w... 透视计算!wpk辅助器安装,wpk脚本下载,最新技巧(有挂教学);1、系统规律教程、辅助透视等服务,...
德扑之星有作弊!wepoke辅... 德扑之星有作弊!wepoke辅助,(WEpoke)都是真的是有挂,详细教程(有挂攻略);德扑之星有作...
wpk发牌逻辑!aapoker... wpk发牌逻辑!aapoker猫腻,(wepoke)竟然是有挂,解密教程(有挂介绍)1、在wpk发牌...
透视科技!wepoker辅助透... 透视科技!wepoker辅助透视软件,aapoker辅助器怎么用,玩家必看教程(有挂攻略)一、aap...
德扑之星辅助器购买!aapok... 德扑之星辅助器购买!aapoker有挂,(wepoKE)一贯是有挂,存在挂教程(有挂技巧)暗藏猫腻,...
透视挂!智星菠萝辅助怎么买,德... 透视挂!智星菠萝辅助怎么买,德普之星透视辅助ios,分享认知(有挂黑科技)辅助器中分为三种模型:软件...
透视科技!aapoker透视脚... 透视科技!aapoker透视脚本,wpk辅助器下载,一起来讨论(有挂详情);辅助器中分为三种模型:软...
德扑ai智能!WePoKe外挂... 德扑ai智能!WePoKe外挂,(wepoKE)切实真的有挂,安装教程(有挂脚本)1、每一步都需要思...
透视黑科技!wpk有脚本吗,w... 透视黑科技!wpk有脚本吗,wpk辅助器安装,重大通报(有挂总结);1、系统规律教程、辅助透视等服务...
德扑之星辅助器购买!微扑克全自... 德扑之星辅助器购买!微扑克全自动机器人,(WEPOke)原来是真的有挂,黑科技教程(有挂攻略);1、...