Integrate Kinde with ASP.NET using Open ID Connect
SDKs and APIs
Kinde auth can be integrated into your application without the need for an SDK. Follow the appropriate guide to secure your API or use OpenID Connect to secure your web application:
The Kinde .NET SDK allows developers to quickly and securely call the Kinde Management API. The Kinde SDK is available from the Nuget package repository at https://www.nuget.org/packages/Kinde.SDK
yourapp.kinde.com.Use Dotnet CLI or NuGet CLI to add packages in your project.
Dotnet CLI:
dotnet add package Kinde.SDKNuGet:
NuGet\Install-Package Kinde.SDKThis 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.
Create and authorize a new client:
var client = new KindeClient(new ApplicationConfiguration("<your-kinde-domain>", "", ""), new KindeHttpClient());await client.Authorize(new ClientCredentialsConfiguration("<your-client-id>", "", "<your-client-secret>", "https://<your-kinde-domain>/api"));Replacing <your-kinde-domain> with your Kinde domain, <your-client-id> and <your-client-secret> with your machine to machine app keys.
The client can be used to call the management API. For example, listing users:
var usersApi = new UsersApi(client);var users = await usersApi.GetUsersAsync();foreach (var user in users.Users){ Console.WriteLine($"Id: {user.Id}, Email: {user.Email}, Name: {user.FirstName} {user.LastName}.");}Note this requires the read:users scope to be added to the API in the machine to machine application in Kinde.
An example of creating an organization then renaming it:
var orgApi = new OrganizationsApi(client);var newOrg = await orgApi.CreateOrganizationAsync(new CreateOrganizationRequest("My new organization"));
var response = await orgApi.UpdateOrganizationAsync(newOrg.Organization.Code, new UpdateOrganizationRequest(){ Name = "A different name});Note this requires the create:organizations and update:organizations scopes to be added to the API in the machine to machine application in Kinde.
For full details of the available management API functions, see the Kinde Management API specification.
To revoke an access or refresh token, call the /oauth2/revoke endpoint with your client credentials and the token to revoke.
using System.Net.Http.Headers;using System.Text;
var httpClient = new HttpClient();var credentials = Convert.ToBase64String( Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));
var request = new HttpRequestMessage(HttpMethod.Post, "https://your-subdomain.kinde.com/oauth2/revoke");request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);request.Content = new FormUrlEncodedContent(new[]{ new KeyValuePair<string, string>("token", tokenToRevoke), new KeyValuePair<string, string>("token_type_hint", "access_token") // or "refresh_token"});
var response = await httpClient.SendAsync(request);This example creates a new HttpClient for clarity. In production, reuse a single instance or inject one via IHttpClientFactory to avoid socket exhaustion under load.
A successful revocation returns HTTP 200. Once revoked, the token can no longer be used to authenticate requests.
If you need help getting Kinde connected, contact us at support@kinde.com.