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

相关内容

热门资讯

出现新变化!智星菠萝有挂吗,功... 出现新变化!智星菠萝有挂吗,功夫川麻老是输什么情况,都是存在有辅助脚本(哔哩哔哩)1、很好的工具软件...
目前来看!德州局怎么透视,陕西... 目前来看!德州局怎么透视,陕西三代实战技巧,一贯是真的有辅助工具(哔哩哔哩)小薇(辅助器软件下载)致...
近日!werplan免费挂下载... 近日!werplan免费挂下载,科乐填大坑破解游戏,一贯是有辅助脚本(哔哩哔哩)1、打开软件启动之后...
最终!来玩app 德州 辅助,... 最终!来玩app 德州 辅助,随意玩房卡代理有挂吗,一直是真的有辅助攻略(哔哩哔哩)1、随意玩房卡代...
今天下午!aa poker透视... 今天下午!aa poker透视软件,边锋干瞪眼脚本,竟然真的有辅助攻略(哔哩哔哩)1)边锋干瞪眼脚本...
突发!hhpoker外开挂靠谱... 突发!hhpoker外开挂靠谱吗,超级三加一辅助软件,果然有辅助app(哔哩哔哩)1、突发!hhpo...
记者获悉!wpk可以作必弊吗,... 记者获悉!wpk可以作必弊吗,奇迹陕西麻将辅助器,切实是有辅助方法(哔哩哔哩)1、实时奇迹陕西麻将辅...
长期以来!wepoker私人局... 长期以来!wepoker私人局透视教程,潮汕汇app透视软件,竟然真的是有辅助方法(哔哩哔哩)1、潮...
连日来!wepoker辅助器官... 连日来!wepoker辅助器官方,凑一桌游戏辅助器怎么安装,一直存在有辅助脚本(哔哩哔哩)运凑一桌游...
反观!poker辅助器免费安装... 反观!poker辅助器免费安装,逍遥辅助器,其实真的是有辅助软件(哔哩哔哩)1、金币登录送、破产送、...