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

相关内容

热门资讯

分享透视"WePOK... 分享透视"WePOKer辅助"开挂(透视)辅助安装(重大通报细节揭秘)分享透视"WePOKer辅助"...
科技开挂!蜜蜂大厅辅助插件,美... 大家好,今天小编来为大家解答蜜蜂大厅辅助插件这个问题咨询软件客服可以免费测试直接加微信(136704...
正版透视"WePok... 正版透视"WePoker透视插件怎么安装"开挂(透视)辅助神器(玩家必看教程玩家教程)正版透视"We...
分析辅助!来来拼十软件脚本,h... 分析辅助!来来拼十软件脚本,hhpoker德州挂真的有吗(一分钟教你开挂辅助安装)1、下载安装好hh...
曝光透视"wpk账号... 曝光透视"wpk账号胜利太低"开挂(透视)辅助脚本(重磅来袭解密教程)曝光透视"wpk账号胜利太低"...
分析开挂!来来拼十辅助,微信小... 【亲,微信小程序广东雀神智能插件 这款游戏可以开挂的,确实是有挂的,很多玩家在这款微信小程序广东雀神...
盘点透视"wepok... 盘点透视"wepoker透视脚本配置"开挂(透视)辅助工具(玩家必备教程新版2026教程)盘点透视"...
盘点辅助!如何购买广东雀神智能... 盘点辅助!如何购买广东雀神智能插件,吉祥填大坑脚本小程序(普及知识开挂辅助平台);无需打开直接搜索加...
分析透视"wepok... 分析透视"wepoker辅助器介绍"开挂(透视)辅助脚本(一分钟教你详细教程)分析透视"wepoke...
通报开挂!蜜瓜大厅小程序辅助,... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...