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

相关内容

热门资讯

透视脚本!wepoker辅助器... 透视脚本!wepoker辅助器激活码,wepoker好友局透视,手段教程(竟然有挂)-哔哩哔哩小薇(...
透视规律!wepoker手机助... 透视规律!wepoker手机助手,hhpoker软件靠谱吗,办法教程(有挂细节)-哔哩哔哩1、用户打...
透视能赢!wepoker有透视... 透视能赢!wepoker有透视功能吗,wepoker如何设置透视,妙招教程(的确有挂)-哔哩哔哩1、...
透视安卓版!wepoker辅助... 透视安卓版!wepoker辅助器免费,we poker辅助器下载,学习教程(有挂方略)-哔哩哔哩1、...
透视规律!pokemmo免费脚... 透视规律!pokemmo免费脚本,智星德州可以透视吗,绝活教程(确实有挂)-哔哩哔哩进入游戏-大厅左...
透视智能ai!wepoker破... 透视智能ai!wepoker破解是真的还是假的,约局吧app有挂吗,方案教程(有挂秘诀)-哔哩哔哩1...
透视安装!hhpoker德州挂... 透视安装!hhpoker德州挂真的有吗,werplan怎么辅助,讲义教程(有挂工具)-哔哩哔哩1、进...
透视了解!aapoker破解侠... 透视了解!aapoker破解侠是真的吗,wepoker私人局俱乐部,技法教程(有挂工具)-哔哩哔哩a...
辅助透视!wepoker辅助器... 辅助透视!wepoker辅助器激活码,德州圈脚本,资料教程(有挂透视)-哔哩哔哩进入游戏-大厅左侧-...
透视辅助!wepoker手机版... 透视辅助!wepoker手机版辅助,约局吧辅助器,方案教程(有挂方法)-哔哩哔哩透视辅助!wepok...