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

相关内容

热门资讯

黑科技安卓版!德扑之星如何开房... 黑科技安卓版!德扑之星如何开房间(黑科技)太坑了有挂(安装教程黑科技方法)-哔哩哔哩1、在德扑之星如...
黑科技讲解!wepoke有软件... 黑科技讲解!wepoke有软件吗(透视)原先是有挂(有挂插件挂)-哔哩哔哩;最新版2024是一款经典...
黑科技透明!红龙扑克是正规的吗... 黑科技透明!红龙扑克是正规的吗(黑科技ai)太坑了真的是有挂(德州教程黑科技教程)-哔哩哔哩1、许多...
黑科技了解!德扑ai智能机器人... 1、黑科技了解!德扑ai智能机器人代理(透视)确实真的是有挂(有挂安装)-哔哩哔哩(UU poker...
黑科技安卓版!wopoker手... 黑科技安卓版!wopoker手机辅助(ai代打)太坑了真的有挂(AI教程黑科技工具)-哔哩哔哩1、完...
黑科技总结!aa poker智... 黑科技总结!aa poker智能ai辅助介绍(黑科技ai)切实存在有挂(有挂安装)-哔哩哔哩关于aa...
黑科技安装!aapoker有后... 黑科技安装!aapoker有后台操控吗(智能ai)太坑了真的有挂(黑科技教程黑科技辅助)-哔哩哔哩;...
黑科技ai代打!苹果菠萝德州辅... 黑科技ai代打!苹果菠萝德州辅助神器(智能ai)原生是有挂(有挂测试)-哔哩哔哩;最新版2024是一...
黑科技安卓版!wepoke a... 黑科技安卓版!wepoke app(透视)太坑了是有挂(曝光教程黑科技解密)-哔哩哔哩;一、wepo...
黑科技苹果版!哈糖大菠萝切牌规... 黑科技苹果版!哈糖大菠萝切牌规律(辅助挂)先前是有挂(有挂后台)-哔哩哔哩;亲真的是有正版授权,小编...