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透视... 您好,安徽麻将这款游戏可以开挂的,确实是有挂的,需要了解加微【485275054】很多玩家在这款游戏...
WPK有透视透视学习!德普之星... WPK有透视透视学习!德普之星私人局透视,WPKai多功能透视攻略1、进入到德普之星私人局透视是否有...
专业讨论开挂!和顺互娱麻将ai... 您好,和顺互娱麻将这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款...
WPK有透视辅助器指南书!we... WPK有透视辅助器指南书!wepoker作弊辅助,智星菠萝德州ai多功能辅助器工具1、wepoker...
WPK作弊开挂资料!wepok... WPK作弊开挂资料!wepoker底牌透视,WePoKerai多功能开挂脚本wepoker底牌透视透...
重大推荐辅助器!欢乐卡五星ai... 重大推荐辅助器!欢乐卡五星ai辅助器多功能插件,先前真的有辅助器脚本积累;近期一款 AI 黑科技工具...
推荐一款!辅助!乐吧游戏ai辅... 推荐一款!辅助!乐吧游戏ai辅助多功能插件,素来存在有辅助app总结是一款可以让一直输的玩家,快速成...
WPK有透视辅助器经验!wep... WPK有透视辅助器经验!wepoker辅助器最新版本更新内容,wpkai多功能辅助器技巧1、进入游戏...
推荐十款辅助挂!哥哥杭州麻将a... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
WPK辅助透视操作!wepok... WPK辅助透视操作!wepoker有用吗,aapokerai多功能透视攻略1、完成wepoker有用...