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

相关内容

热门资讯

关于“乐乐游戏辅助器”原生有辅... 关于“乐乐游戏辅助器”原生有辅助器(有挂功能)这是一款可以让一直输的玩家,快速成为一个“必胜”的ai...
科技新动态“红中血流攻略”素来... 科技新动态“红中血流攻略”素来有辅助开挂挂(有挂方法);亲,红中血流攻略这款游戏原来确实可以开挂的,...
今日公布“丽水都来大菠萝脚本辅... 您好:这款丽水都来大菠萝脚本辅助游戏是可以开挂的,确实是有挂的,很多玩家在这款丽水都来大菠萝脚本辅助...
发现一款“广西老友玩老师输怎么... 发现一款“广西老友玩老师输怎么版”一向有辅助开挂工具(有挂总结);亲,广西老友玩老师输怎么版这款游戏...
透视数据“epoker透视”原... 透视数据“epoker透视”原先有辅助挂(有挂方针)这是一款可以让一直输的玩家,快速成为一个“必胜”...
记者发布“友玩广西辅助联系方式... 记者发布“友玩广西辅助联系方式”原生有开挂辅助挂(有挂技术);无需打开直接搜索薇:136704302...
玩家必看科普“蜀渝牌乐汇修改器... 玩家必看科普“蜀渝牌乐汇修改器”从前有开挂辅助脚本(证实有挂)1、下载安装好蜀渝牌乐汇修改器,进入游...
透视计算“白金岛小程序插件最新... >>您好:白金岛小程序插件最新版本更新内容确实是有挂的,很多玩家在这款白金岛小程序插件最新版本更新内...
必知教程“欢聚水鱼智能辅助脚本... 大家好,今天小编来为大家解答欢聚水鱼智能辅助脚本怎么用这个问题咨询软件客服可以免费测试直接加微信(1...
揭秘一下“海豹3+1辅助器”原... 揭秘一下“海豹3+1辅助器”原先有辅助工具(发现有挂) 了解更多开挂安装加(136704302)微信...