OAuth2NetCore 2.0.0

dotnet add package OAuth2NetCore --version 2.0.0
                    
NuGet\Install-Package OAuth2NetCore -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OAuth2NetCore" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OAuth2NetCore" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="OAuth2NetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OAuth2NetCore --version 2.0.0
                    
#r "nuget: OAuth2NetCore, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OAuth2NetCore@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OAuth2NetCore&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=OAuth2NetCore&version=2.0.0
                    
Install as a Cake Tool

OAuth2NetCore

OAuth 2.0 / OpenID Connect 协议核心库,提供授权码(含 PKCE)、客户端凭证、资源所有者密码、隐式与刷新令牌等标准 grant type 的服务端实现。netstandard2.0 目标。

主要类型

  • IAuthServer / DefaultAuthServer — Token / Authorize / EndSession / ClearToken 请求处理器。
  • AuthServerOptions — 服务端配置(PKCE 必需、签名算法、各 store/factory 注册)。
  • ClientOptions — 客户端配置(OAuth client 接入参数)。
  • IClientValidator / DefaultClientValidator — Basic Auth 提取与客户端凭证、redirect URI、grant、scope、response type 校验。
  • IPkceValidator / DefaultPkceValidator — PKCE S256 / plain 校验。
  • ITokenGenerator / DefaultTokenGenerator — 基于 Microsoft.IdentityModel.JsonWebTokens 的 JWT 签发,默认算法 PS256。
  • ISecretEncryptor / X509SecretEncryptor — RSA OAEP-SHA256 加密器(v2.0+)。
  • IClientStore / IAuthCodeStore / IRefreshTokenInfoStore / IStateStore — 各存储接口。内存版默认实现包含在主库中;Redis 实现在 OAuth2NetCore.Redis 包。

快速接入

services.AddOAuth2AuthServer(options => {
    options.SecurityKeyProviderFactory = _ => new X509SecurityKeyProvider(cert);
    options.ClientStoreFactory          = _ => myClientStore;
    options.RefreshTokenInfoStore       = _ => myRefreshTokenStore;
    options.StateStoreFactory           = _ => myStateStore;
    options.TokenClaimBuilderFactory    = _ => new MyTokenClaimBuilder();
    options.ResourceOwnerValidatorFactory = sp => new MyResourceOwnerValidator(...);
    // options.SigningAlgorithm   = SecurityAlgorithms.RsaSsaPssSha256;  // 默认 PS256
    // options.PKCERequired       = true;   // 默认开
    // options.AllowPlainPkce     = false;  // 默认拒绝 plain,仅过渡期可放行
});

// ...

app.UseEndpoints(endpoints => {
    endpoints.MapPost("/connect/token",        authServer.TokenRequestHandler);
    endpoints.MapGet ("/connect/authorize",    authServer.AuthorizeRequestHandler);
    endpoints.MapGet ("/connect/endsession",   authServer.EndSessionRequestHandler);
    endpoints.MapPost("/connect/endsession",   authServer.ClearTokenRequestHandler);
});

v2.0 安全加固要点

v2.0 是 major security release。完整漏洞清单与下游升级指南见仓库内:

从 v1.x 升级前必读——RSA padding、PKCE 默认值、Cookie 名等均为 breaking change。

仓库

https://github.com/Lukiya/oauth2net

协议

GPL-3.0-or-later

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on OAuth2NetCore:

Package Downloads
SyncSoft.App

An app framework for SyncSoft Inc.

OAuth2NetCore.Redis

An oauth2 framework for dotnet

OAuth2NetCore.Host

An oauth2 framework for dotnet

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 218 5/19/2026
1.3.1 3,167 1/6/2025
1.3.0 11,894 2/15/2023
1.2.2 3,498 2/16/2023
1.2.1 52,724 9/9/2021
1.0.1 787 9/12/2021
Loading failed