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

相关内容

热门资讯

黑科技辅助!wopoker分析... 黑科技辅助!wopoker分析器(ai辅助)总是存在有挂(有挂苹果版本)-哔哩哔哩;最新版2024是...
黑科技辅助!微扑克靠谱吗(辅助... 黑科技辅助!微扑克靠谱吗(辅助挂)一贯真的是有挂(有挂大厅房)-哔哩哔哩;科技安装教程;136704...
黑科技辅助!菠萝德州偷偷看功能... 黑科技辅助!菠萝德州偷偷看功能(辅助挂)固有存在有挂(有挂俱乐部)-哔哩哔哩;实战中需综合运用上述技...
黑科技存在!wepoke辅助器... 自定义wepoke辅助器真的有效果吗系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专...
黑科技计算!fishpoker... 黑科技计算!fishpoker大菠萝外挂(黑科技ai)真是存在有挂(有挂线上)-哔哩哔哩;玩家必备必...
黑科技计算!微扑克ai机器人怎... 黑科技计算!微扑克ai机器人怎么回事(ai代打)原先真的有挂(有挂辅助)-哔哩哔哩是由北京得微扑克a...
黑科技辅助挂!wpk微扑克俱乐... 1、黑科技辅助挂!wpk微扑克俱乐部(ai辅助)先前真的是有挂(有挂神器)-哔哩哔哩2、进入游戏-大...
黑科技好友房!微扑克这软件有问... 黑科技好友房!微扑克这软件有问题吗(ai辅助)原生真的有挂(有挂插件)-哔哩哔哩1、不需要AI权限,...
黑科技中牌率!wepoke辅助... 黑科技中牌率!wepoke辅助德之星(ai代打)往昔是真的有挂(有挂机制)-哔哩哔哩是一款可以让一直...
辅助黑科技!wpk有外挂吗(透... 辅助黑科技!wpk有外挂吗(透视)原来真的是有挂(有挂后台)-哔哩哔哩1、许多玩家不知道wpk有外挂...