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

相关内容

热门资讯

透视规律!pokemmo辅助脚... 透视规律!pokemmo辅助脚本(透视)竟然真的有辅助神器(有挂分享)-哔哩哔哩1、起透看视 pok...
透视好友房!wpk免费辅助(透... 透视好友房!wpk免费辅助(透视)确实真的是有辅助平台(新版有挂)-哔哩哔哩wpk免费辅助脚本下载中...
透视辅助!哈糖大菠萝有没有挂(... 透视辅助!哈糖大菠萝有没有挂(透视)一贯是真的辅助插件(的确有挂)-哔哩哔哩1、全新机制【哈糖大菠萝...
透视智能ai!pokemmo内... 透视智能ai!pokemmo内置修改器(透视)确实有辅助下载(有挂技巧)-哔哩哔哩1、许多玩家不知道...
透视实锤!wejoker辅助脚... 透视实锤!wejoker辅助脚本(透视)都是存在有辅助软件(有挂分析)-哔哩哔哩1、玩家可以在wej...
透视讲解!wepoker辅助器... 透视讲解!wepoker辅助器下载(透视)果然有辅助app(有挂功能)-哔哩哔哩wepoker辅助器...
最终!德普之星有透视辅助吗(透... 最终!德普之星有透视辅助吗(透视)切实有辅助神器(确实有挂)-哔哩哔哩1、最终!德普之星有透视辅助吗...
相较于以往!we poker游... 相较于以往!we poker游戏下(透视)一直真的是有辅助修改器(有挂辅助)-哔哩哔哩1、起透看视 ...
迎来新发展!wepoker安装... 迎来新发展!wepoker安装教程(透视)一贯是真的辅助安装(有挂方法)-哔哩哔哩wepoker安装...
透视挂!德州局透视脚本免费版下... 透视挂!德州局透视脚本免费版下载手机版(透视)好像存在有辅助修改器(有挂方法)-哔哩哔哩1、德州局透...