Casdoor.Client
1.16.0
dotnet add package Casdoor.Client --version 1.16.0
NuGet\Install-Package Casdoor.Client -Version 1.16.0
<PackageReference Include="Casdoor.Client" Version="1.16.0" />
<PackageVersion Include="Casdoor.Client" Version="1.16.0" />
<PackageReference Include="Casdoor.Client" />
paket add Casdoor.Client --version 1.16.0
#r "nuget: Casdoor.Client, 1.16.0"
#:package Casdoor.Client@1.16.0
#addin nuget:?package=Casdoor.Client&version=1.16.0
#tool nuget:?package=Casdoor.Client&version=1.16.0
Casdoor .NET SDK
The Casdoor's SDK for .NET/ASP.NET Core, which will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch.
Packages
This SDK is built using the following packages for different platforms:
Casdoor Client
Casdoor.Client is a base package for the specific platform SDKs. It contains follow features.
- CasdoorClient: A API client implementation for the Casdoor. You can use to call the Casdoor APIs.
Usage
var httpClient = new HttpClient();
var client = new CasdoorClient(HttpClient, new CasdoorOptions{
Endpoint = "https://door.casdoor.com",
OrganizationName = "casbin", // your Casdoor organization
ApplicationName = "app-example", // your Casdoor application
ApplicationType = "native", // webapp, webapi or native
ClientId = "b800a86702dd4d29ec4d", // your Casdoor application's client ID
ClientSecret = "1219843a8db4695155699be3a67f10796f2ec1d5", // your Casdoor application's client secret
});
// Request tokens (You should enable credentials flow in your Casdoor application)
var token = await client.RequestClientCredentialsTokenAsync();
client.SetBearerToken(token);
var currentUser = client.ParseJwtToken(token.AccessToken);
// Request user info
var users = await client.GetUsersAsync();
// Request roles
var roles = await client.GetRolesAsync();
// Request Permissions
var persmissions = await client.GetPermissionsAsync();
var policy = new CasdoorPermissionRule()
{
Id = $"{currentUser.Owner}/{persmissions.First().Name}",
V0 = $"{currentUser.Owner}/{currentUser.Name}",
V1 = "example-resource",
V2 = "example-action"
};
var isPermissionAvaliable = await client.EnforceAsync(policy);
- CasdoorOptions (Updating)
- Extensions (Updating)
Casdoor AspNetCore
Getting started
- Add the following settings about casdoor in your appsettings.json file:
{
"Casdoor": {
"Endpoint": "<your Casdoor endpoint>",
"OrganizationName": "<your Casdoor organization>",
"ApplicationName": "<your Casdoor application>",
"ApplicationType": "webapp", // webapp or webapi (webapi is not yet supported)
"ClientId": "<your Casdoor application's client ID>",
"ClientSecret": "<your Casdoor application's client secret>",
// Optional: The callback path that the client will be redirected to
// after the user has authenticated. default is "/casdoor/signin-callback"
"CallbackPath": "/callback",
// Optional: Whether require https for casdoor endpoint
"RequireHttpsMetadata": false,
// Optional: The scopes that the client will request
"Scopes": [
"openid",
"profile",
"email",
]
}
}
- Add the following code to your webapp:
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCasdoor(builder.Configuration.GetSection("Casdoor"))
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);
- Now you can use the Casdoor authentication scheme in your webapp!
Samples
1. MVC sample
It is a MVC webapp that uses Casdoor authentication. The default settings use the public demo Casdoor and Casnode configuration, you can directly start the webapp by running:
dotnet run
Or change the settings in the appsettings.json according to your deployed casdoor configuration.README.md
License
This project is licensed under the Apache 2.0 license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 is compatible. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
-
.NETFramework 4.6.1
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
-
.NETFramework 4.6.2
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
-
.NETStandard 2.0
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
-
.NETStandard 2.1
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
-
net5.0
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
-
net6.0
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
-
net7.0
- IdentityModel (>= 5.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.34.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.16.0)
- System.Net.Http.Json (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Casdoor.Client:
| Package | Downloads |
|---|---|
|
Casdoor.AspNetCore
The Casdoor's SDK for .NET, which will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Casdoor.Client:
| Repository | Stars |
|---|---|
|
AIDotNet/Thor
Thor is a powerful artificial intelligence model management tool, whose main purpose is to achieve unified management and use of multiple AI models. Through Thor, users can easily manage and utilize numerous AI models
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.16.0 | 11,703 | 4/27/2024 |
| 1.15.0 | 2,932 | 2/17/2024 |
| 1.13.0 | 289 | 2/3/2024 |
| 1.12.0 | 1,225 | 11/19/2023 |
| 1.11.0 | 314 | 11/12/2023 |
| 1.10.2 | 287 | 11/4/2023 |
| 1.10.1 | 310 | 10/30/2023 |
| 1.10.0 | 361 | 10/10/2023 |
| 1.9.1 | 276 | 10/5/2023 |
| 1.9.0 | 375 | 9/6/2023 |
| 1.8.1 | 261 | 9/5/2023 |
| 1.8.0 | 292 | 8/31/2023 |
| 1.7.0 | 293 | 8/31/2023 |
| 1.6.0 | 237 | 8/30/2023 |
| 1.5.0 | 320 | 8/30/2023 |
| 1.4.0 | 269 | 8/27/2023 |
| 1.3.0 | 447 | 8/5/2023 |
| 1.2.1 | 305 | 8/1/2023 |
| 1.2.0 | 336 | 7/25/2023 |
| 1.1.0 | 301 | 7/25/2023 |