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

相关内容

热门资讯

透视好友(wepoke插件)德... 透视好友(wepoke插件)德扑之星ai代打(详细辅助黑科技教程)一直真的是有挂1、这是跨平台的德扑...
aapoker发牌机制!pok... aapoker发牌机制!pokerrrr2辅助神器,(wepower德州)从来存在有挂(详细辅助必胜...
透视存在(wePOke)透明挂... 这是一款非常优秀的wepoke有没有挂 ia辅助检测软件,能够让你了解到wepoke有没有挂中牌率当...
透视中牌率(德州AI智能辅助机... 您好,德州AI智能辅助机器人这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
wepower有外挂!德州透视... 此外,数据分析德州(wepower有外挂)辅助神器app还具备辅助透视行为开挂功能,通过对客户wep...
透视透视挂(wepoKe)外挂... 《透视透视挂(wepoKe)外挂透明挂辅助插件(wepower辅助器)从前真的是有挂(详细透视系统教...
透视app(wepoke真的有... 透视app(wepoke真的有挂)微扑克有辅助挂吗(详细辅助可靠教程)从来有挂1、微扑克有辅助挂ai...
WPK透视辅助!nzt德州辅助... WPK透视辅助!nzt德州辅助软件,(aApoker)从来真的是有挂(详细透视玩家教你);玩家必备必...
透视中牌率(wEpOke)透视... 此外,数据分析德州(wepower有外挂)辅助神器app还具备辅助透视行为开挂功能,通过对客户wep...
透视美元局(wepoke计算辅... 透视美元局(wepoke计算辅助)微扑克ai操作(详细辅助黑科技教程)一向有挂1)wepoke计算辅...