Clinically.Kinde.Authentication 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Clinically.Kinde.Authentication --version 1.1.1                
NuGet\Install-Package Clinically.Kinde.Authentication -Version 1.1.1                
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="Clinically.Kinde.Authentication" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Clinically.Kinde.Authentication --version 1.1.1                
#r "nuget: Clinically.Kinde.Authentication, 1.1.1"                
#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.
// Install Clinically.Kinde.Authentication as a Cake Addin
#addin nuget:?package=Clinically.Kinde.Authentication&version=1.1.1

// Install Clinically.Kinde.Authentication as a Cake Tool
#tool nuget:?package=Clinically.Kinde.Authentication&version=1.1.1                

Integrating Kinde Auth with .NET8 Blazor Apps

This library assists with integrating Kinde with .NET applications. It is still in development but usable. There may be breaking changes from version to version for now.

Add the following NuGet package: Clinically.Kinde.Authentication

The following needs to be in your appSettings.json on the server:

"Kinde": {
  "Authority": "<From Kinde>",
  "ClientId": "<From Kinde>",
  "ClientSecret": "<From Kinde>",
  "ManagementApiClientId": "<From Kinde>",
  "ManagementApiClientSecret": "<From Kinde>",
  "SignedOutRedirectUri": "https://localhost:5001/signout-callback-oidc",
  "JwtAudience": "<From Kinde - Audience for API, if using JWT Bearer Auth in addition to Identity>",
},
"AppConfig": {
  "BaseUrl": "https://localhost:5001"
}

You can omit JwtAudience if you are not using JWT Bearer Authentication.

If you want users to log in to your MVC / Razor Page / Blazor app, add then need the following to your Program.cs:

builder.Services.AddKindeIdentityAuthentication(opt =>
{
    opt.UseMemoryCacheTicketStore = false; // optional - default to false
}); 

If you want to add JwtBearer Authentication to your API, add this to your Program.cs (remember to add the JwtAudience to your appSettings.json):

builder.Services.AddKindeJwtBearerAuthentication();

Then add the standard authorization services:

builder.Services.AddAuthorization();

For Blazor WASM, you also need to add this to Program.cs on the client:

builder.Services.AddKindeWebAssemblyAuthentication();

Roles

You can use the standard Authorize attribute:

[Authorize(Roles = "Admin")]

Permissions

In order to add authorization policies for your Kinde permissions:

builder.Services
    .AddAuthorizationBuilder()
    .AddKindePermissionPolicies<Permissions>();

Then create a Permissions class that contains all the Kinde permissions you want to use:

public class Permissions
{
    public const string MyPermissionName = "myPermissionNameInKinde";
}

Then you can use the permissions in your controllers or Razor pages:

[Authorize(Policy = Permissions.MyPermissionName)]

Notes

  • You need to go to the Tokens section of your app, and enable the Roles and Email claims in the access token.
  • In order to access the management API (e.g. to add users programmatially etc), inject KindeManagementClient into your services. Note you will need a separate M2M app in Kinde for this, with access to the Management API.
  • You can also inject KindeUserManager instead of the standard UserManager to get access to Kinde-specific methods.
  • Inject BlazorUserAccessor to get access to the current user in your Blazor components.

I've only recently worked out how to tie all this together, so some bits may not be entirely required etc. Raise an issue if you notice any problems.

To Do List:

  • Feature flags not currently implemented (but will work the same way as Permissions)
  • Support more claims/properties in the strongly typed user objects
Product 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. 
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.3.0 98 5/1/2024
1.2.4 71 4/29/2024
1.2.3 115 4/16/2024
1.2.2 103 4/10/2024
1.2.1 92 4/10/2024
1.2.0 105 4/10/2024
1.1.2 112 4/8/2024
1.1.1 107 4/8/2024
1.1.0 113 4/8/2024
1.0.3 118 4/7/2024
1.0.2 114 4/5/2024
1.0.1 106 4/4/2024
1.0.0 107 4/4/2024