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

相关内容

热门资讯

2分钟细说"蜀山四川... 2分钟细说"蜀山四川辅助器下载渠道有哪些"开挂(脚本)辅助脚本有挂教学-揭秘教程;无需打开直接搜索微...
免费测试版"敢拍小程... >>您好:敢拍小程序靠谱吗确实是有挂的,很多玩家在这款敢拍小程序靠谱吗游戏中打牌都会发现很多用户的牌...
今日头条"中至赣牌圈... 今日头条"中至赣牌圈挂件价格明细"开挂(插件)辅助插件有挂攻略-AI教程中至赣牌圈挂件价格明细ai黑...
一分钟了解"福建微乐... 一分钟了解"福建微乐小程序修改器"开挂(软件)辅助软件有挂猫腻-大神讲解福建微乐小程序修改器ai黑科...
技术分享"圣盛鄂州晃... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
透视挂"福建十三水辅... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
透视挂"四川麻将口诀... 透视挂"四川麻将口诀顺口溜"开挂(平台)辅助平台有挂细节-曝光教程>>您好:软件加薇13670430...
透视系统"微信小游戏... 透视系统"微信小游戏辅助器"开挂(软件)辅助软件了解有挂-扑克教程;无需打开直接搜索打开薇:1367...
今日焦点"白银胡乐亲... 白银胡乐亲友房开挂教程视频分享装挂详细步骤在当今的网络游戏中,白银胡乐亲友房作为一种经典的娱乐方式,...
透视黑科技"家乡大二... 透视黑科技"家乡大二技巧"开挂(透视)辅助透视有挂细节-安装教程>>您好:软件加薇136704302...