SetNet.Auth.OAuth 1.1.0

dotnet add package SetNet.Auth.OAuth --version 1.1.0
                    
NuGet\Install-Package SetNet.Auth.OAuth -Version 1.1.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="SetNet.Auth.OAuth" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.Auth.OAuth" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.Auth.OAuth" />
                    
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 SetNet.Auth.OAuth --version 1.1.0
                    
#r "nuget: SetNet.Auth.OAuth, 1.1.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 SetNet.Auth.OAuth@1.1.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=SetNet.Auth.OAuth&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.Auth.OAuth&version=1.1.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>

SetNet.Auth.OAuth

OAuth 2.0 / OpenID Connect authenticator for SetNet.Auth.

An IAuthenticator that validates access (JWT) tokens issued by a standards-compliant identity provider — Auth0, Azure AD / Entra ID, Keycloak, Google, Cognito, and friends — against the provider's published signing keys. Keys are discovered from the authority's /.well-known/openid-configuration (JWKS) and refreshed automatically as they rotate, so you never hard-code or manually rotate keys. Use this when your clients already log in through an external provider and hand SetNet the resulting access token.

For tokens you sign yourself with a static key (shared secret or your own RSA key), use SetNet.Auth.Jwt instead.

Install

dotnet add package SetNet
dotnet add package SetNet.Auth
dotnet add package SetNet.Auth.OAuth

Setup

AuthRuntime.Enable();     // once at startup, both ends, before creating client/server

Server

Point the authenticator at your provider's authority and hand it to UseAuth. UseAuth installs the enforced inbound gate from SetNet.Auth: until a peer authenticates, its application frames are dropped and only the auth handshake passes.

using SetNet.Auth;
using SetNet.Auth.OAuth;

var auth = new OpenIdConnectAuthenticator(
    authority:    "https://my-tenant.auth0.com/",   // its /.well-known/openid-configuration is fetched
    audience:     "my-game-api",                     // expected `aud`; null to skip audience checks
    accountClaim: "sub");                             // claim carrying the account id

server.UseAuth(auth, new AuthOptions());

Provider authority examples:

Provider Authority
Auth0 https://my-tenant.auth0.com/
Azure AD / Entra https://login.microsoftonline.com/{tenant}/v2.0
Keycloak https://kc.example.com/realms/{realm}
Google https://accounts.google.com
AWS Cognito https://cognito-idp.{region}.amazonaws.com/{poolId}

Client

Clients present the provider's access token as their auth token — no OAuth-specific code beyond the base SetNet.Auth client hook:

// a provider that returns a fresh access token on every (re)connect:
var auth = client.UseAuth(tokenProvider: () => identityClient.GetAccessTokenAsync());

// or a fixed token you already obtained:
client.UseAuth(accessToken);

API

OpenIdConnectAuthenticator : IAuthenticator

Member Purpose
new OpenIdConnectAuthenticator(authority, audience? = null, accountClaim = "sub") build from a provider authority URL
Task<AuthResult> AuthenticateAsync(string token) called by the server per handshake; validates against the cached JWKS

Validation checks signing key, issuer (the authority's own issuer), audience (when audience is non-null), and lifetime, with a 30-second clock skew. The account id comes from accountClaim, falling back to sub; a missing id fails the token. The discovery document + JWKS are fetched once and cached by a ConfigurationManager, which refreshes them on its own schedule as keys rotate.

Notes

  • Use over TLS. The access token is a bearer credential — sniffable and replayable if the connection isn't encrypted. Run SetNet with TLS-over-TCP or wss:// (via SetNet.WebSockets).
  • Outbound access required. The server must be able to reach the authority's /.well-known/openid-configuration and JWKS endpoints to validate tokens.
  • Audience matters. Validate audience in production so tokens minted for a different app of the same tenant can't be replayed against your server; pass null only if you deliberately accept any audience.
  • Session resume, multi-session policy, and the session store come from SetNet.Auth's AuthOptions — this package only decides whether a token is valid and who it belongs to.

Documentation & source

License

MIT

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 129 7/2/2026