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

相关内容

热门资讯

程序员教你“wrpoker透视... 您好:wrpoker透视挂真的吗的软件,软件加客服确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
玩家科普“wepoker透视挂... 您好,wepoker透视挂的玩法这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】...
一起来探讨“wepokerpu... 您好:wepokerpus透视挂是真的假的的软件,软件加客服确实是有挂的,很多玩家在这款游戏中打牌都...
每日必看推荐“wepoker透... 每日必看推荐“wepoker透视挂安装”开挂辅助平台(透视)必胜教程是一款可以让一直输的玩家,快速成...
最新通报“wepokerplu... 最新通报“wepokerplus德州局辅助”开挂辅助挂(透视)安装教程是一款可以让一直输的玩家,快速...
推荐一款“wepoker机制发... 推荐一款“wepoker机制发冤家牌”开挂辅助工具(透视)细节揭秘是一款可以让一直输的玩家,快速成为...
发现玩家“wepoker有透视... >>您好:wepoker有透视吗确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别好,总...
记者爆料“wepoker辅助挂... 记者爆料“wepoker辅助挂有没有”开挂辅助插件(透视)科技教程是一款可以让一直输的玩家,快速成为...
玩家必看科普“微扑克辅助器有用... 无需打开直接搜索;操作使用教程:玩家必看科普“微扑克辅助器有用吗”开挂辅助插件(透视)细节方法1、界...
科技介绍“wpk透视挂免费测试... 您好:wpk透视挂免费测试这款游戏是可以开挂的,软件加【添加微信客服136704302】确实是有挂的...