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

相关内容

热门资讯

解密关于!德扑之心免费透视,德... 解密关于!德扑之心免费透视,德州hhpoker脚本,本来有挂(有挂细节)1、公共底牌简单,透视插件操...
最新研发!wepoker辅助真... 最新研发!wepoker辅助真的假的,pokemmo免费脚本,原来是真的有挂(有挂规律)1、起透看视...
科技通报!wpk俱乐部辅助器,... 科技通报!wpk俱乐部辅助器,werplan免费挂下载,好像真的是有挂(有挂细节)1、进入到是否有挂...
揭秘一下!wepoker好友助... 揭秘一下!wepoker好友助力码,wepoker有没有挂,确实是有挂(有挂详情)1、进入游戏-大厅...
今日百科!wepoker私人局... 今日百科!wepoker私人局外卦,wepoker怎么破解游戏,总是是真的有挂(讲解有挂)1、每一步...
关于!hhpoker可以开挂吗... 关于!hhpoker可以开挂吗,约局吧app有挂吗,其实真的是有挂(有挂猫腻)1、在插件功能辅助器技...
玩家必备科普!wepoker怎... 玩家必备科普!wepoker怎么破解游戏,wepoker辅助器免费,确实真的有挂(真的有挂)wepo...
实测必看!pokeplus脚本... 实测必看!pokeplus脚本,hhpoker外挂靠谱吗,其实真的是有挂(有挂总结)1、透视辅助软件...
必看攻略!wpk作弊最怕三个东... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
免费测试版!德普之星透视辅助,... 免费测试版!德普之星透视辅助,哈糖大菠萝怎么开挂,一直存在有挂(有挂头条)1)辅助插件:进一步探索辅...