Skip to content

Tanyuu/casdoor-dotnet-sdk-example

 
 

Repository files navigation

Casdoor .NET SDK Samples

Here are Casdoor .NET SDK samples for casdoor-dotnet-sdk.

Sample Name Dependencies Description
ConsoleApp .NET 6.0 or newer Sample of a simple console app
MvcApp .NET 6.0 or newer Sample of a MVC webapp

This sample simply shows how to use Casdoor.Client package. It is an API client implementation for the Casdoor, used to call the Casdoor APIs.

Quickstart

git clone https://github.com/casdoor/casdoor-dotnet-sdk-example.git
cd casdoor-dotnet-sdk-example
dotnet run --project ConsoleApp

Some information will be displayed on the console, which is from the Program.cs file and has been processed by Casdoor.

Configuration

Now open Program.cs file and you can see the following code:

var httpClient = new HttpClient();
var options = new CasdoorOptions
{
    Endpoint = "https://door.casdoor.com",
    OrganizationName = "casbin",
    ApplicationName = "app-build-in",
    ApplicationType = "native",
    ClientId = "b800a86702dd4d29ec4d",
    ClientSecret = "1219843a8db4695155699be3a67f10796f2ec1d5",
    CallbackPath = "/callback",
    RequireHttpsMetadata = true,
    Scope = "openid profile email"
};
var client = new CasdoorClient(httpClient, options);

The meanings of some fields are explained as follows:

Name Must Description
Endpoint Yes Your Casdoor host.
OrganizationName Yes The organization that the application belongs to.
ApplicationName Yes Your application name.
ApplicationType Yes Your application type. Must be webapp, webapi or native.
ClientId Yes Your OAuth client id.
ClientSecret Yes Your OAuth client secret.
CallbackPath No The callback path that the client will be redirected to after the user has authenticated. Default is "/casdoor/signin-callback".
RequireHttpsMetadata No Whether requires https for Casdoor endpoint.
Scope No The scopes that the client is requesting.

For more information, refer to https://github.com/casdoor/casdoor-dotnet-sdk/blob/master/README.md.

This sample shows how to use Casdoor.AspNetCore package for Casdoor authentication.

Quickstart

git clone https://github.com/casdoor/casdoor-dotnet-sdk-example.git
cd casdoor-dotnet-sdk-example
dotnet run --project MvcApp

The default settings use the public demo Casdoor and Casnode configuration. Now Casdoor is listening on http://localhost:5000 and https://localhost:5001, and you can open your browser and visit any of them.

mvcapp1

Input admin and 123 to sign in, or you can register a new account.

Configure your Casdoor

You can change the settings in the appsettings.json file according to the deployed Casdoor configuration. Here are relevant settings in this sample.

"Casdoor": {
    "Endpoint": "https://door.casdoor.com",
    "OrganizationName": "casbin",
    "ApplicationName": "app-example",
    "ApplicationType": "webapp",
    "ClientId": "b800a86702dd4d29ec4d",
    "ClientSecret": "1219843a8db4695155699be3a67f10796f2ec1d5",
    "CallbackPath": "/callback",
    "RequireHttpsMetadata": false
},

The meanings of some fields are explained as follows:

Name Must Description
Endpoint Yes Your Casdoor host.
OrganizationName Yes The organization that the application belongs to.
ApplicationName Yes Your application name.
ApplicationType Yes Your application type. Must be webapp or webapi. (webapi is not yet supported)
ClientId Yes Your OAuth client id.
ClientSecret Yes Your OAuth client secret.
CallbackPath No The callback path that the client will be redirected to after the user has authenticated. Default is "/casdoor/signin-callback".
RequireHttpsMetadata No Whether requires https for Casdoor endpoint.

In addition, some launch settings are placed in the Properties/launchSettings.json file, such as the listening URLs http://localhost:5000;https://localhost:5001, to facilitate your use of this sample. This file is not necessary.

For more information, refer to https://github.com/casdoor/casdoor-dotnet-sdk/blob/master/README.md.

About

.NET example based on casdoor-dotnet-sdk

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 50.2%
  • HTML 39.2%
  • CSS 8.7%
  • JavaScript 1.9%