.NET SDK
SDKs and APIs
Kinde supports the OpenID Connect (OIDC) protocol, which allows integration with the authentication services built into ASP.NET, without the need for a separate SDK.
This guide walks through the steps of integrating Kinde auth into an ASP.NET web application using OpenID Connect.
A complete sample project can be found in the .NET starter kit.
Install the OpenID connect package:
Add authentication services (typically in program.cs
):
Add the authentication and authorization middleware:
Configure authentication in appsettings.json
, replacing the placeholders <your_kinde_domain>
, <your_client_id>
and <your_client_secret>
, with your application keys found in Kinde.
In Kinde, add an allowed callback to your application. For local development this callback will look like the following, where <local_port>
should be replaced with the port generated for your project:
Similarly, add an allowed logout:
The OpenID Connect middleware will automatically handle requests to these routes.
Access tokens contain information (claims) about what a user is authorized to do when they sign in. In Kinde, you can create policies to manage authorization.
Create a policy that allows only users with certain permission claims, e.g. read:weather
.
Set up permissions in Kinde.
Note roles defined in Kinde do not map to roles as defined in ASP.NET, so the related functionality, such as RequireRole()
, cannot be used.
To protect routes, add the [Authorize]
attribute (from the Microsoft.AspNetCore.Authorization
package) to any controllers or actions required.
For example, allow access only to users that satisfy the policy defined in the previous section:
See the ASP.NET Core documentation for more details on authorization.
Razor pages can be secured by specifying the routes in service configuration, for example:
See Microsoft documentation for more details about authorizing Razor pages.
You’ll want to log a user out of your application as well as Kinde, for example:
Kinde has some additional options such as specifying the organization to log into. These parameters can be specified in the OnRedirectToIdentityProvider
event in the OpenID connect options. For example: