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、许多玩...
黑科技最新(微扑克辅助工具怎么... 黑科技最新(微扑克辅助工具怎么下载)外挂透明挂辅助技巧(透视)好像真的有挂(黑科技工具)1、玩家可以...
黑科技辅助(微扑克辅助插件挂)... 黑科技辅助(微扑克辅助插件挂)外挂透明挂辅助挂(透视)竟然有挂(黑科技揭秘);1、下载好微扑克辅助插...
黑科技规律(微扑克数据辅助软件... 黑科技规律(微扑克数据辅助软件)外挂黑科技辅助app(透视)一贯有挂(黑科技细节);1、不需要AI权...
黑科技脚本(德州微扑克辅助)外... 黑科技脚本(德州微扑克辅助)外挂透视辅助安装(透视)一贯是真的有挂(黑科技技巧);1、该软件可以轻松...
黑科技有挂(红龙扑克辅助器)外... 黑科技有挂(红龙扑克辅助器)外挂黑科技辅助插件(透视)一直是真的有挂(黑科技黑科技)亲,关键说明,红...
黑科技规律(wepoke透明挂... 黑科技规律(wepoke透明挂辅助)外挂透视辅助挂(透视)本来真的有挂(黑科技脚本)1、wepoke...
黑科技软件(德扑之星作弊事件)... 黑科技软件(德扑之星作弊事件)外挂透明挂辅助挂(透视)总是存在有挂(黑科技黑科技)德扑之星作弊事件软...
黑科技规律(德州之星辅助软件)... 黑科技规律(德州之星辅助软件)外挂黑科技辅助神器(透视)切实真的有挂(黑科技方法)1、全新机制【德州...
黑科技app(德州之星辅助挂)... 黑科技app(德州之星辅助挂)外挂透明挂辅助app(透视)本来真的有挂(黑科技规律);1、德州之星辅...