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、任何微乐小程序...
透视黑科技!德普之星私人局辅助... 透视黑科技!德普之星私人局辅助免费,德普之星透视辅助插件(透视)都是真的是有挂(真的有挂)-哔哩哔哩...
值得注意的是!全民比鸡bug,... 值得注意的是!全民比鸡bug,wejoker辅助软件价格,操作教程(了解有挂)-哔哩哔哩1)wejo...
透视app!德扑圈透视,德普之... 透视app!德扑圈透视,德普之星私人局辅助免费(透视)好像有挂(有挂秘笈)-哔哩哔哩1、很好的工具软...
目前来看!新漫游正版辅助软件,... 目前来看!新漫游正版辅助软件,雀姬胡牌辅助,绝活儿教程(有挂解密)-哔哩哔哩新漫游正版辅助软件破解侠...
透视能赢!德普之星辅助工具如何... 透视能赢!德普之星辅助工具如何打开,德普之星辅助器怎么用(透视)确实真的是有挂(证实有挂)-哔哩哔哩...
这一问题亟待解决!pokerw... 这一问题亟待解决!pokerworld辅助器,新海贝之城脚本,操作教程(今日头条)-哔哩哔哩新海贝之...
透视教程!德扑圈透视,德扑圈有... 透视教程!德扑圈透视,德扑圈有透视吗(透视)切实存在有挂(有挂教程)-哔哩哔哩1、进入游戏-大厅左侧...
此事引发网友热议!天天贵州万能... 此事引发网友热议!天天贵州万能辅助器,pokemmo辅助器脚本下载,阶段教程(有挂技巧)-哔哩哔哩p...