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

相关内容

热门资讯

解密关于!智星菠萝透视,南昌微... 解密关于!智星菠萝透视,南昌微乐自建房辅助,原来有开挂辅助教程(竟然有挂);无需打开直接搜索薇:13...
科普!湖北卡五星教程辅助,蛮王... 科普!湖北卡五星教程辅助,蛮王大厅辅助,盘点开挂辅助教程(详细教程);无需打开直接搜索打开薇:136...
专业讨论!微信小程序游戏辅助,... 专业讨论!微信小程序游戏辅助,wepoker私人局辅助器,详细开挂辅助教程(有挂辅助);无需打开直接...
玩家必看教程!边锋老友圈怎么开... 玩家必看教程!边锋老友圈怎么开辅助,衢州都莱辅助器下载,分析开挂辅助教程(了解有挂);无需打开直接搜...
玩家必看科普!边锋干橙眼外挂免... 玩家必看科普!边锋干橙眼外挂免费,同城游辅助软件,发现开挂辅助教程(果真有挂);无需打开直接搜索薇:...
一分钟了解!桃乐甘肃麻将辅助软... 一分钟了解!桃乐甘肃麻将辅助软件,天天互娱辅助器免费下载,通报开挂辅助教程(有挂细节)1、下载安装好...
技术分享!三哥玩摆头辅助,约战... 技术分享!三哥玩摆头辅助,约战沙城挂机辅助,原来有开挂辅助教程(有挂教学);无需打开直接搜索加薇13...
重大通报!决战卡五星作弊,新道... 重大通报!决战卡五星作弊,新道游app辅助器,分享开挂辅助教程(有挂详细);无需打开直接搜索加薇13...
玩家必看教程!互游辅助脚本,川... 玩家必看教程!互游辅助脚本,川南休闲辅助,传授开挂辅助教程(有挂助手);无需打开直接搜索打开薇:13...
科技通报!方片十三张透视脚本,... 科技通报!方片十三张透视脚本,三哥玩辅助器免费下载,原来有开挂辅助教程(有挂细节);无需打开直接搜索...