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... 教程辅助!畅享徐州麻将辅助ai透视挂攻略,畅享徐州麻将果然是有作弊器(有辅助挂辅助)1、不需要AI权...
玩家攻略推荐!米多多麻将辅助a... 玩家攻略推荐!米多多麻将辅助ai透视挂软件,米多多麻将都是有开挂(有辅助挂总结)1、每一步都需要思考...
信息共享!朋朋棋牌辅助ai透视... 信息共享!朋朋棋牌辅助ai透视挂app,朋朋棋牌本来是有辅助器(有辅助挂详细)1、朋朋棋牌公共底牌简...
玩家科普!玉兔互娱辅助ai透视... 玩家科普!玉兔互娱辅助ai透视挂方法,玉兔互娱切实有作弊器(有辅助挂功能)1)玉兔互娱有没有挂:进一...
推荐一款!宁夏麻将辅助ai透视... 推荐一款!宁夏麻将辅助ai透视挂app,宁夏麻将好像存在有作弊器(有辅助挂分析)1、宁夏麻将透视辅助...
详细说明!闲来广东麻将17辅助... 详细说明!闲来广东麻将17辅助ai透视挂app,闲来广东麻将17都是真的是有透视器(有辅助挂规律)1...
盘点一款!52麻将辅助ai透视... 您好,52麻将这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款...
一分钟了解!趣玩贵州麻将辅助a... 一分钟了解!趣玩贵州麻将辅助ai透视挂软件,趣玩贵州麻将总是真的是有外挂(有辅助挂解密)1、趣玩贵州...
科普分享!和和绥北麻将辅助ai... 科普分享!和和绥北麻将辅助ai透视挂方法,和和绥北麻将一贯是真的有透视器(有辅助挂辅助)1)和和绥北...
科技通报!卡五星辅助ai透视挂... 科技通报!卡五星辅助ai透视挂脚本,卡五星都是是真的有辅助器(确实有辅助挂)1、卡五星破解器简单,卡...