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

相关内容

热门资讯

黑科技app(云扑克app)g... 自定义governorofpoker3系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克...
黑科技辅助(aapoker能玩... 黑科技辅助(aapoker能玩)wpk德州总是有挂!太嚣张了竟然是有挂(2024已更新)(哔哩哔哩)...
黑科技辅助(Epoker外挂)... 黑科技辅助(Epoker外挂)AApOKER确实是有挂!太无语了原本是真的有挂(2023已更新)(哔...
黑科技美元局(德扑之星概率)x... 黑科技美元局(德扑之星概率)x-poker原来存在有挂!太嚣张了固有真的是有挂(2026已更新)(哔...
黑科技挂(wpk助手)wpk线... 1、黑科技挂(wpk助手)wpk线上先前真的有挂!太离谱了果然是有挂(2024已更新)(哔哩哔哩)。...
黑科技辅助挂(微扑克线上)微扑... 黑科技辅助挂(微扑克线上)微扑克俱乐部切实有挂!太离谱了总是有挂(2025已更新)(哔哩哔哩);致您...
黑科技攻略(wpk猫腻)微扑克... 黑科技攻略(wpk猫腻)微扑克德州原先是真的有挂!太嚣张了起初真的有挂(2022已更新)(哔哩哔哩)...
黑科技中牌率(WPK)AAPO... 黑科技中牌率(WPK)AAPOKER原生是有挂!太无语了总是是真的有挂(2023已更新)(哔哩哔哩)...
黑科技美元局(德州ai智能)f... 黑科技美元局(德州ai智能)fishpoker俱乐部素来真的有挂!太离谱了都是有挂(2021已更新)...
黑科技讲解(红龙扑克机制)众合... 黑科技讲解(红龙扑克机制)众合推扑克起初真的是有挂!太无语了最初是有挂(2022已更新)(哔哩哔哩)...