Torii.Backend
0.0.3
dotnet add package Torii.Backend --version 0.0.3
NuGet\Install-Package Torii.Backend -Version 0.0.3
<PackageReference Include="Torii.Backend" Version="0.0.3" />
<PackageVersion Include="Torii.Backend" Version="0.0.3" />
<PackageReference Include="Torii.Backend" />
paket add Torii.Backend --version 0.0.3
#r "nuget: Torii.Backend, 0.0.3"
#:package Torii.Backend@0.0.3
#addin nuget:?package=Torii.Backend&version=0.0.3
#tool nuget:?package=Torii.Backend&version=0.0.3
Torii.Backend
Backend SDK for torii — verify end-user JWTs without a per-request round trip and manage users from your .NET server.
v0.x — API may still change.
Setup
Sign in to app.torii.so and from your dashboard copy:
- your issuer URL (e.g.
https://acme.torii.so) - a secret key (
sk_test_…for development,sk_live_…for production)
- your issuer URL (e.g.
Install the package:
dotnet add package Torii.Backend # ASP.NET Core adapter (optional) dotnet add package Torii.Backend.AspNetCoreTargets
net8.0.Verify an end-user JWT:
using Torii.Backend; var auth = await TokenVerifier.VerifyTokenAsync( token, new VerifyOptions(Issuer: "https://acme.torii.so")); Console.WriteLine($"{auth.UserId} {auth.EnvironmentId} {auth.EmailVerified}");The first call fetches the issuer's JWKS; subsequent calls reuse the cache and rotate keys automatically via
Microsoft.IdentityModel'sConfigurationManager. No round-trip per request.Call the backend REST API:
using Torii.Backend; using var torii = ToriiClient.Create( secretKey: Environment.GetEnvironmentVariable("TORII_SECRET_KEY")!); var user = await torii.Users.GetAsync(userId);Default base URL is
https://api.torii.so. Override with theapiUrlargument for staging or self-hosted. Pass anHttpClient(e.g., fromIHttpClientFactory) to share connection pooling or inject test fakes.
ASP.NET Core
using Torii.Backend.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddAuthentication(ToriiAuthenticationOptions.DefaultScheme)
.AddTorii(opts =>
{
opts.Issuer = "https://acme.torii.so";
});
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/me", (HttpContext ctx) =>
{
var auth = (Auth)ctx.Items[ToriiAuthenticationHandler.AuthItemKey]!;
return Results.Ok(new { auth.UserId, auth.EnvironmentId });
}).RequireAuthorization();
app.Run();
The handler maps the verified JWT into a ClaimsPrincipal (claims: sub, pid, iss, email_verified, profile_complete, impersonating, locale) and also stashes the raw Auth object on HttpContext.Items[ToriiAuthenticationHandler.AuthItemKey] for direct access.
Backend REST API
var page = await torii.Users.ListAsync(limit: 50);
var user = await torii.Users.CreateAsync(new CreateUserInput(Email: "x@y.com"));
await torii.Users.BanAsync(user.Id);
var sessions = await torii.Sessions.ListForUserAsync(user.Id);
await torii.Sessions.RevokeAllForUserAsync(user.Id);
Partial updates (Users.UpdateAsync)
UpdateUserInput uses Patch<T> so each field has three states:
- Set — change the field to a value:
Patch<string>.Set("Ada") - Clear — explicitly null the field server-side:
Patch<string>.Set(null) - Omit — don't touch the field (default): leave the property at its initial value
await torii.Users.UpdateAsync(user.Id, new UpdateUserInput
{
Name = Patch<string>.Set("Ada Lovelace"),
Phone = Patch<string>.Set(null), // sends "phone": null
// Locale omitted — left untouched
DateOfBirth = Patch<string>.Set("1815-12-10"),
});
C# nullable reference types only distinguish two states (null vs value), which conflates "leave alone" with "clear". Patch<T> is the third state.
Building from source
git clone https://github.com/Torii-ApS/torii-sdk-dotnet
cd torii-sdk-dotnet
dotnet build
dotnet test
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net8.0
- JsonSubTypes (>= 2.0.1)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.2.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.2.0)
- Microsoft.IdentityModel.Tokens (>= 8.2.0)
- Newtonsoft.Json (>= 13.0.3)
- Polly (>= 8.4.2)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Torii.Backend:
| Package | Downloads |
|---|---|
|
Torii.Backend.AspNetCore
ASP.NET Core authentication handler for the torii backend SDK. |
GitHub repositories
This package is not used by any popular GitHub repositories.