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

相关内容

热门资讯

黑科技神器!we-poker有... 黑科技神器!we-poker有挂吗,aapoker有内部好嘛,线上教程(有挂详情)-哔哩哔哩;人气非...
黑科技辅助挂!wepoke有辅... 黑科技辅助挂!wepoke有辅助挂,德扑之星软件,2025新版教程(有挂方法)-哔哩哔哩1.wepo...
黑科技软件!智星德州菠萝怎么看... 黑科技软件!智星德州菠萝怎么看有没有开挂,微扑克有辅助挂,安装教程(有挂介绍)-哔哩哔哩1、超多福利...
黑科技透明挂!wepoke黑科... 黑科技透明挂!wepoke黑科技,微扑克ai辅助神器,新2025版(有挂详情)-哔哩哔哩;无聊就玩这...
黑科技神器!德州之星有机器人吗... 黑科技神器!德州之星有机器人吗,德扑之星软件有猫腻吗,wepoke教程(有挂黑科技)-哔哩哔哩;黑科...
黑科技挂!wepoke软件透明... 黑科技挂!wepoke软件透明挂价格,智星德州菠萝辅助器,辅助教程(有挂规律)-哔哩哔哩;黑科技挂!...
黑科技脚本!wepoke透明挂... 一、wepoke透明挂是真的吗简介了解软件请加微:136704302wepoke透明挂是真的吗是一款...
黑科技脚本!德州ai辅助外挂,... 黑科技脚本!德州ai辅助外挂,红龙扑克辅助器下载,2025新版(有挂教程)-哔哩哔哩1、不需要AI权...
黑科技软件!德扑之星软件模拟器... 黑科技软件!德扑之星软件模拟器,wepower有外挂,详细教程(有挂黑科技)-哔哩哔哩是一款可以让一...
黑科技神器!aa poker有... 黑科技神器!aa poker有没有挂,aapoker外挂,扑克教程(有挂透明)-哔哩哔哩1、构建自己...