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

相关内容

热门资讯

专业透视!智星菠萝辅助,微乐家... 专业透视!智星菠萝辅助,微乐家乡官方app下载,举措教程(有挂秘诀)-哔哩哔哩1、操作简单,无需智星...
普及透视!wpk辅助器,提高微... 普及透视!wpk辅助器,提高微乐运气的方法,资料教程(确实有挂)-哔哩哔哩1、操作简单,无需wpk辅...
必备透视!德州透视是真的假的,... 您好,德州透视是真的假的这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...
解迷透视!wpk德州局怎么透视... 解迷透视!wpk德州局怎么透视,微信微乐游戏辅助脚本,项目教程(讲解有挂)-哔哩哔哩wpk德州局怎么...
解密透视!wepoker养号规... 解密透视!wepoker养号规律,微乐南昌辅助神器,资料教程(有挂秘籍)-哔哩哔哩运wepoker养...
详细透视!wepoker国外版... 详细透视!wepoker国外版透视,微信微乐辅助ios,大纲教程(有挂神器)-哔哩哔哩1、wepok...
必备透视!大菠萝辅助器,微乐小... 必备透视!大菠萝辅助器,微乐小程序礼包码,烘培教程(有挂解密)-哔哩哔哩1、实时大菠萝辅助器透视辅助...
关于透视!拱趴大菠萝开挂方法,... 关于透视!拱趴大菠萝开挂方法,微信小程序游戏破解微乐辅助,举措教程(真的有挂)-哔哩哔哩1、完成拱趴...
普及透视!wepoker插件程... 普及透视!wepoker插件程序激活码,微乐麻将自建房app,策略教程(有挂技术)-哔哩哔哩wepo...
必备透视!德州私人局脚本,微乐... 必备透视!德州私人局脚本,微乐自建房辅助工具在哪,教程书教程(的确有挂)-哔哩哔哩1、首先打开德州私...