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

相关内容

热门资讯

黑科技规律!云扑克德州辅助器(... 黑科技规律!云扑克德州辅助器(aapokerai辅助)本然存在有挂(讲解有挂)-哔哩哔哩,您好,aa...
黑科技美元局!智星德州菠萝开挂... 黑科技美元局!智星德州菠萝开挂(德州辅助神器软件)真是真的是有挂(有挂秘笈)-哔哩哔哩1、起透看视 ...
黑科技神器!聚星扑克有假(aa... 黑科技神器!聚星扑克有假(aa poker有外挂吗)先前有挂(讲解有挂)-哔哩哔哩(1)黑科技神器!...
黑科技好牌!aapoker辅助... 黑科技好牌!aapoker辅助(wepoke智能ai)原来是真的有挂(有挂分享)-哔哩哔哩1、构建自...
黑科技苹果版!wepoke透明... 黑科技苹果版!wepoke透明挂在哪买(微扑克如何让系统发好牌)确实真的是有挂(竟然有挂)-哔哩哔哩...
黑科技游戏!德州AI智能辅助机... 黑科技游戏!德州AI智能辅助机器人(微扑克如何让系统发好牌)都是存在有挂(有挂辅助)-哔哩哔哩1、实...
黑科技挂!wepoke辅助德之... 黑科技挂!wepoke辅助德之星(wepoke透明黑科技)都是有挂(了解有挂)-哔哩哔哩1、每个玩家...
黑科技数据!智星德州菠萝外挂检... 黑科技数据!智星德州菠萝外挂检测(德州ai辅助)本来真的有挂(发现有挂)-哔哩哔哩是一款可以让一直输...
黑科技科技!德扑ai智能工具(... 黑科技科技!德扑ai智能工具(aa poker有外挂吗)真是真的是有挂(竟然有挂)-哔哩哔哩1、实时...
黑科技美元局!云扑克辅助挂(德... 自定义德扑ai智能系统系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管...