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

相关内容

热门资讯

黑科技软件(wepoKE)黑科... 黑科技软件(wepoKE)黑科技透明挂辅助神器(透视)黑科技教程(都是真的是有挂)1、下载好wepo...
黑科技辅助挂(aapokeR)... 黑科技辅助挂(aapokeR)外挂透视辅助方法(透视)黑科技教程(都是是真的有挂)1、许多玩家不知道...
黑科技ai(红龙扑克)外挂辅助... 黑科技ai(红龙扑克)外挂辅助技巧(透视)2025新版技巧(本来是有挂);1、任何红龙扑克ai辅助神...
黑科技免费(wPk)外挂透视辅... 黑科技免费(wPk)外挂透视辅助挂(透视)德州教程(其实是有挂);1、点击下载安装,德州插件透视分类...
黑科技最新(线上wpk德州ai... 黑科技最新(线上wpk德州ai)外挂透视辅助教程(透视)玩家教程(竟然存在有挂);1、每一步都需要思...
黑科技辅助(wEpoke)黑科... 黑科技辅助(wEpoke)黑科技透明挂辅助助手(透视)黑科技教程(都是存在有挂)1、wEpoke系统...
黑科技挂(fishpoker俱... 黑科技挂(fishpoker俱乐部)外挂辅助神器(透视)新版2025教程(确实有挂)1、任何fish...
黑科技规律(wePoKe)黑科... 黑科技规律(wePoKe)黑科技透明挂辅助安装(透视)攻略教程(果然有挂)1、下载好wePoKe辅助...
黑科技私人局(aapokER)... 黑科技私人局(aapokER)外挂辅助下载(透视)玩家教程(都是真的是有挂);1.aapokER a...
黑科技好友(wepOke)黑科... 黑科技好友(wepOke)黑科技透明挂辅助教程(透视)详细教程(真是真的有挂)1、wepOke系统规...