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透视功能下载,微乐贵阳足鸡麻将开挂,绝活儿教程(确实有挂)-哔哩哔哩亲,关键...
有挂透视!佛手大菠萝13道挂哪... 有挂透视!佛手大菠萝13道挂哪里,陕西微乐挖坑小程序脚本,妙招教程(有挂透明挂)-哔哩哔哩1、上手简...
科普透视!wepokerplu... 科普透视!wepokerplus到底是挂了吗,微乐小程序破解,指引教程(有挂秘籍)-哔哩哔哩1、起透...
详细透视!德普之星怎么开辅助,... 详细透视!德普之星怎么开辅助,微乐小程序黑科技辅助工具2026最新推荐,方式教程(有挂详情)-哔哩哔...
分享透视!hhpoker买挂,... 分享透视!hhpoker买挂,微乐家乡麻将辅助,阶段教程(有挂方针)-哔哩哔哩1、该软件可以轻松地帮...
了解透视!德州机器人代打脚本,... 了解透视!德州机器人代打脚本,微乐广西小程序开挂,指引教程(发现有挂)-哔哩哔哩德州机器人代打脚本是...
解谜透视!hhpoker辅助,... 解谜透视!hhpoker辅助,微信小程序游戏充值破解,阶段教程(有挂分享)-哔哩哔哩1、全新机制【h...
推荐透视!hhpoker真的有... 推荐透视!hhpoker真的有透视吗,微乐小程序游戏破解器苹果系统,窍要教程(有挂实锤)-哔哩哔哩1...
了解透视!hhpoker底牌透... 了解透视!hhpoker底牌透视脚本,微信小程序微乐为什么老输,模板教程(有挂存在)-哔哩哔哩1、全...
辅助透视!大菠萝789辅助器下... 辅助透视!大菠萝789辅助器下载,微乐小程序自建房辅助器,绝活教程(有挂神器)-哔哩哔哩大菠萝789...