KeyInteractive.Common.Api.Users
2.0.0
See the version list below for details.
dotnet add package KeyInteractive.Common.Api.Users --version 2.0.0
NuGet\Install-Package KeyInteractive.Common.Api.Users -Version 2.0.0
<PackageReference Include="KeyInteractive.Common.Api.Users" Version="2.0.0" />
<PackageVersion Include="KeyInteractive.Common.Api.Users" Version="2.0.0" />
<PackageReference Include="KeyInteractive.Common.Api.Users" />
paket add KeyInteractive.Common.Api.Users --version 2.0.0
#r "nuget: KeyInteractive.Common.Api.Users, 2.0.0"
#:package KeyInteractive.Common.Api.Users@2.0.0
#addin nuget:?package=KeyInteractive.Common.Api.Users&version=2.0.0
#tool nuget:?package=KeyInteractive.Common.Api.Users&version=2.0.0
Key Interactive.Common.Api.Users
KeyInteractive.Common.Api.Users is the official .NET client for the Key Interactive Users API
("Key Interactive Accounts"). It gives your app a ready-to-use IApiConsumer/ApiConsumer service
wrapping registration, login, enrollment, profile/password management, and the "Sign in with Key
Interactive" flow (Authorize/Consent/Poll) behind simple method calls, instead of writing HTTP
clients by hand.
This package supersedes the older KeyInteractive.API.Common package (namespace
KeyInteractiveCommon) — if you're migrating from it, see the notes at the bottom of this README.
It's built on KeyInteractive.Common.Api,
which provides the generic API-consuming plumbing (response envelope, retry, JWT handling) that
ApiConsumer inherits.
Installation
dotnet add package KeyInteractive.Common.Api.Users
Configuration
Configure your credentials once at startup with ApiSettings.Configure:
using KeyInteractive.Common.Api.Users.Configuration;
using KeyInteractive.Common.Api.Users.Enums;
ApiSettings.Configure(builder => builder
.ConfigureApiKey("your-api-key")
.ConfigureApplicationId("your-application-id")
.SetApiVersion(EApiVersion.V1)
.SetCustomApiBaseUri("https://accounts.keyinteractive.it/")
.ConfigureDeviceInfo(Environment.MachineName, "127.0.0.1")
.Build());
Dependency injection (Blazor Server / ASP.NET Core)
// Program.cs
builder.Services.AddScoped<ITokenProvider, TokenProvider>();
builder.Services.AddHttpClient<IApiConsumer, ApiConsumer>();
ITokenProvider must be registered Scoped: it holds the current user's JWT for one Blazor
circuit. If your site also talks to another API built on KeyInteractive.Common.Api, give that
consumer its own ITokenProvider and a distinct StorageKeyPrefix — see the
KeyInteractive.Common.Api README for
details. This package's own storage key prefix is fixed to "ki" for backward compatibility with
existing sessions.
Usage examples
Register and log in
using KeyInteractive.Common.Api.Users.DTO.UsersApi;
var registration = await apiConsumer.RegisterBasicUser(new BasicUserRegistrationDto
{
Username = "jdoe",
Email = "jdoe@example.com",
Password = "Sup3rSecret!",
ConfirmPassword = "Sup3rSecret!",
DateOfBirth = new DateTime(1990, 1, 1),
AcceptedPrivacy = true,
AcceptedPrivacyDate = DateTime.UtcNow,
});
var login = await apiConsumer.Login(new UserLoginDTO(
loginCredentials: "jdoe@example.com",
password: "Sup3rSecret!",
deviceName: Environment.MachineName,
deviceIp: "127.0.0.1"));
if (login.Success)
{
Console.WriteLine($"Welcome, {login.LoginResponse.ActiveUser.Name}!");
}
Read the current user's profile
var profile = await apiConsumer.GetProfile();
if (profile.Success)
{
Console.WriteLine(profile.UserProfile.Email);
}
"Sign in with Key Interactive" — server-to-server token exchange
Use a separate ApiConsumer instance configured with your third-party application's own
ApiKey/ApplicationKey (not the Key Interactive site's own):
var exchange = await apiConsumer.ExchangeAuthorizationCode(new AuthorizeTokenExchangeDto
{
Code = codeFromRedirect,
RedirectUri = "https://your-app.example.com/callback",
});
if (exchange.Success)
{
// apiConsumer is now authenticated as the linked user (SetAuthTokens was applied automatically)
var user = exchange.TokenData.ActiveUser;
}
For the "standard"/polling mode (no redirect_uri), poll instead:
var poll = await apiConsumer.PollAuthorizeToken(new AuthorizePollDto { State = yourGeneratedState });
if (poll.Success)
{
// token acquired, same as ExchangeAuthorizationCode
}
else if (poll.ErrorMessage == "authorization_pending")
{
// keep polling
}
See IApiConsumer for the full list of available operations (registration, enrollment,
profile/password management, and the full Authorize/Consent/Poll flow).
Migrating from KeyInteractive.API.Common
- Namespace changed from
KeyInteractiveCommon.*toKeyInteractive.Common.Api.Users.*(DTOs, responses, models, enums) andKeyInteractive.Common.Api.*(the response envelopeKiApiResponse/KiApiResponseData, now shared plumbing). IApiConsumer/ApiConsumerpublic surface and behavior are unchanged: same constructor signature, same endpoints, same retry/token-rotation behavior. Existing logged-in users are unaffected — the refresh token storage key prefix (ki_auth_token/ki_auth_refresh_token) is unchanged.ApiSettings.Configure(...)usage inProgram.csis unchanged.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- KeyInteractive.Common.Api (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.