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

相关内容

热门资讯

出乎意料的是!aapoker辅... 出乎意料的是!aapoker辅助怎么用,德普之星透视辅助,一直存在有挂(新版有挂)1)德普之星透视辅...
明白辅助挂!智星德州插件怎么下... 明白辅助挂!智星德州插件怎么下载,德普之星辅助工具如何设置,都是真的有挂(有人有挂)1、每一步都需要...
不少玩家反映!pokernow... 不少玩家反映!pokernow辅助工具,德扑之星透视,果然存在有挂(确实有挂)1、德扑之星透视公共底...
2026版攻略!aapoker... 2026版攻略!aapoker万能辅助器,智星菠萝透视,果然是真的有挂(有挂规律)1、2026版攻略...
围绕透视问题!德普之星透视,如... 围绕透视问题!德普之星透视,如何下载德普之星辅助软件,其实存在有挂(的确有挂)1、超多福利:超高返利...
针对!wepoker怎么买辅助... 针对!wepoker怎么买辅助,德扑之星怎么开辅助,总是是真的有挂(有挂方式)1、德扑之星怎么开辅助...
现场直击!wepoker开脚本... 您好,德扑之星透视免费这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩...
据悉!德普之星怎么设置埋牌,德... 据悉!德普之星怎么设置埋牌,德扑之星辅助工具如何打开,切实确实有挂(有挂方法)德扑之星辅助工具如何打...
黑科技辅助挂!德普辅助app,... 黑科技辅助挂!德普辅助app,智星德州插件2024最新版,真是真的有挂(有挂教程)智星德州插件202...
复盘辅助挂!wpk私人局有透视... 复盘辅助挂!wpk私人局有透视吗,德扑之星的辅助工具介绍,都是存在有挂(真的有挂)一、德扑之星的辅助...