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

相关内容

热门资讯

推荐攻略!哈糖大菠萝提高胜率,... 推荐攻略!哈糖大菠萝提高胜率,心悦俱乐部游戏辅助,分析开挂辅助教程(有挂秘诀)1、下载安装好哈糖大菠...
重大通报!四川游戏家园辅助软件... 您好:四川游戏家园辅助软件合法吗这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很...
分享给玩家!多乐游戏小程序辅助... 分享给玩家!多乐游戏小程序辅助器免费,葫芦娃辅助软件,推荐开挂辅助教程(有挂教学)1、下载安装好多乐...
教学盘点!决战十三水辅助,萍乡... 教学盘点!决战十三水辅助,萍乡滚筒四幅攻略,关于开挂辅助教程(有挂方法);无需打开直接搜索加(薇:1...
一分钟了解!微信新海贝之城辅助... 一分钟了解!微信新海贝之城辅助,友友联盟辅助免费下载,了解开挂辅助教程(有挂存在);无需打开直接搜索...
研究成果!微信边锋干橙眼辅助,... 研究成果!微信边锋干橙眼辅助,浙江宝宝游戏辅助,必看开挂辅助教程(发现有挂);无需打开直接搜索薇:1...
分享实测!榆林打锅子辅助器,微... 分享实测!榆林打锅子辅助器,微信微乐游戏辅助脚本,传授开挂辅助教程(真的有挂);无需打开直接搜索打开...
一分钟了解!闲来辅助神器怎么下... 一分钟了解!闲来辅助神器怎么下载,赣牌圈破解器,分享开挂辅助教程(有挂讲解);无需打开直接搜索打开薇...
玩家实测!微乐自建房脚本免费下... 玩家实测!微乐自建房脚本免费下载,三江互娱辅助,教会开挂辅助教程(有挂工具);无需打开直接搜索加(薇...
分享一款!广东潮汕雀友会插件,... 分享一款!广东潮汕雀友会插件,金杯竞技辅助,教会开挂辅助教程(有挂技巧);无需打开直接搜索加薇136...