WojtJ.Kinde.IdentityAuthentication 1.0.12

Suggested Alternatives

Clinically.Kinde.Authentication

Additional Details

This package has been moved to a new repository and tidied up - strongly suggest changing to the new package. Usage remains the same.

dotnet add package WojtJ.Kinde.IdentityAuthentication --version 1.0.12
NuGet\Install-Package WojtJ.Kinde.IdentityAuthentication -Version 1.0.12
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="WojtJ.Kinde.IdentityAuthentication" Version="1.0.12" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WojtJ.Kinde.IdentityAuthentication --version 1.0.12
#r "nuget: WojtJ.Kinde.IdentityAuthentication, 1.0.12"
#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 WojtJ.Kinde.IdentityAuthentication as a Cake Addin
#addin nuget:?package=WojtJ.Kinde.IdentityAuthentication&version=1.0.12

// Install WojtJ.Kinde.IdentityAuthentication as a Cake Tool
#tool nuget:?package=WojtJ.Kinde.IdentityAuthentication&version=1.0.12

Integrating Kinde Auth with .NET8 Blazor Server Apps

This is a quick sample of integrating Kinde Authentication with Blazor apps using AspNet core identity

Either fork the repo and use it, or add the following NuGet package: WojtJ.Kinde.IdentityAuthentication

It needs lots of improvements, but is a reasonable starting point.

The following needs to be in your appSettings.json:

"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 then need the following in your Program.cs (I will soon add something so you can just add the section):

builder.Services.AddKindeAuthentication(opt =>
{
    opt.UseJwkTokenValidation = false; // default to false
    opt.UseMemoryCacheTicketStore = false; // default to false
}); 

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 BlazorServerUserAccessor to get access to the current user in your Blazor server-rendered components.

I've only just recently worked out how to tie all this together, so some bits may not be entirely required etc. Take this as a proof of concept at the moment 😃

To Do List:

  • Feature flags not currently implemented (but will work the same way as Permissions)
  • Nuget package
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.0.12 127 3/31/2024
1.0.6 84 3/30/2024
1.0.5 85 3/30/2024
1.0.2 87 3/29/2024
1.0.1 87 3/29/2024
1.0.0 97 3/29/2024