The Casgate's SDK for .NET/ASP.NET Core, which will allow you to easily connect your application to the Casgate authentication system without having to implement it from scratch.
Note: This SDK is currently in beta and is not yet ready for use.
This SDK is built using the following packages for different platforms:
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.
var httpClient = new HttpClient();
var client = new CasdoorClient(HttpClient, new CasdoorOptions{
Endpoint = "https://door.casdoor.com",
OrganizationName = "build-in",
ApplicationName = "app-build-in",
ApplicationType = "native", // webapp, webapi or native
ClientId = "<your client id>",
ClientSecret = "<your 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)
- Add the following settings about casdoor in your appsettings.json file:
{
"Casdoor": {
"Endpoint": "<your casdoor host>",
"OrganizationName": "<your organization name>",
"ApplicationName": "<your application name>",
"ApplicationType": "webapp", // webapp or webapi (webapi is not yet supported)
"ClientId": "<your client id>",
"ClientSecret": "<your 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!
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.
This project is licensed under the Apache 2.0 license.