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

相关内容

热门资讯

最新技巧"家乡大二有... 【亲,家乡大二有没有辅助 这款游戏可以开挂的,确实是有挂的,很多玩家在这款家乡大二有没有辅助中打牌都...
发现玩家"wepok... 发现玩家"wepoker有辅助插件吗"开挂(软件)辅助软件有挂神器-我来教教你wepoker有辅助插...
如何分辨真伪"新天道... 如何分辨真伪"新天道辅助软件怎么样"开挂(神器)辅助神器有挂辅助-2026教程>>您好:软件加136...
一分钟了解"欢聚水鱼... 欢聚水鱼辅助插件 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1...
总算了解"五十k辅助... 总算了解"五十k辅助"开挂(透视)辅助透视果真有挂-AI教程>>您好:软件加薇136704302中联...
盘点十款"poker... 盘点十款"pokernow辅助工具"开挂(脚本)辅助脚本有挂规律-我来教教你 【无需打开直接搜索加薇...
科技新动态"四川麻将... 科技新动态"四川麻将口诀顺口溜"开挂(平台)辅助平台真的有挂-总结教程 【无需打开直接搜索加薇136...
总算明白"微信闲来辅... 总算明白"微信闲来辅助神器"开挂(平台)辅助平台确实有挂-2026新版总结这是一款可以让一直输的玩家...
透视肯定"摸一把游戏... 您好:这款摸一把游戏跑得快辅助游戏是可以开挂的,确实是有挂的,很多玩家在这款摸一把游戏跑得快辅助游戏...
透视规律"八仙游戏辅... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...