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

相关内容

热门资讯

据目击者称!wepoker游戏... 据目击者称!wepoker游戏安装教程,微信小程序微乐辅助器教程,普及透视(有挂方法)-哔哩哔哩1、...
脚本揭幕!wepoker永久免... 脚本揭幕!wepoker永久免费脚本,we poker辅助器v3.3(透视)一直真的是有插件(哔哩哔...
针对!wepoker私人辅助器... 针对!wepoker私人辅助器,微乐手游脚本辅助,辅助透视(揭秘有挂)-哔哩哔哩1、进入到wepok...
脚本开挂!aapoker怎么开... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这款游戏中打...
透视教学!wpk辅助,微乐陕西... 透视教学!wpk辅助,微乐陕西小程序辅助,详情透视(有挂秘笈)-哔哩哔哩wpk辅助是不是有人用挂微扑...
脚本透视!德普之星透视辅助插件... 脚本透视!德普之星透视辅助插件,德普之星辅助软件(透视)好像真的有攻略(哔哩哔哩)1、下载好脚本下载...
有了最新消息!uupoker有... 有了最新消息!uupoker有透视吗,微乐陕西麻将破解,总结脚本(有挂教学)-哔哩哔哩1、uupok...
透视辅助!aapoker透视方... 透视辅助!aapoker透视方法,aapoker怎么提高中牌率(透视)其实存在有工具(哔哩哔哩);1...
透视数据!hhpoker辅助器... 透视数据!hhpoker辅助器视频,微乐家乡自建房辅助app,透视透视(有挂总结)-哔哩哔哩1、游戏...
透视揭露!wepoker破解器... 透视揭露!wepoker破解器,wepoker游戏安装教程(透视)果然是真的神器(哔哩哔哩)1、完成...