SapphireDb logo SapphireDb

Server - Configuration

SapphireDb has different options to configure your application to do what you want.

General

To configure the SapphireDb-Server pass the options object in the service configuration.

\f:(csharp:Startup.cs) public class Startup\n {\n \tpublic void ConfigureServices(IServiceCollection services)\n \t{\n \t\t//Register services\n \t\tservices.AddSapphireDb(new SapphireDatabaseOptions());\n \t}\n }

Load settings from configuration

You can also pass a configuration section when creating the database options. This will load the settings from it.

\f:(csharp:StartupWithSettings.cs) public class Startup\n {\n \tpublic void ConfigureServices(IServiceCollection services)\n \t{\n \t\t//Register services\n \t\tservices.AddSapphireDb(new SapphireDatabaseOptions(Configuration.GetSection("SapphireDb")));\n \t}\n } \f:(json:appsettings.json) {\n \t"SapphireDb": {\n \t\t"ApiConfigurations": [\n \t\t\t{\n \t\t\t\t"Secret": "F6249E39DD6FBF6AA29D1D943390288392E6A819DC17FA057934EC3D48EAC06A06DE51B6DF6DBCD0BA8049C13B151EC71DEE0AD20C9E74237B8990D997E35968",\n \t\t\t\t"Key": "webapp",\n \t\t\t\t"Name": "Example Web Client"\n \t\t\t}\n \t\t]\n \t}\n }
All settings are loaded from coniguration files.
You only have to set CanExecuteCommand and IsAllowedToSendMessages from code manually.

Strict mode

The settings contain configuration for authentication. The default configuration is very weak and allows every user to do everything. It is highly recommended to define custom options for critical parts. You can enable the strict mode of the options to run on a higher security level.

\f:(csharp:Startup.cs) public class Startup\n {\n \tpublic void ConfigureServices(IServiceCollection services)\n \t{\n \t\t//Register services\n \t\tservices.AddSapphireDb(new SapphireDatabaseOptions(true));\n \t}\n }

Available options

ApiConfigurations

If you want to restrict access to the server you can define api configurations. You should define a configuration for every client application.
Every configuration consists of a key, a secret and a readable name.
Default: []

\f:(csharp:ExampleCode.cs) public class Startup\n {\n \tpublic void ConfigureServices(IServiceCollection services)\n \t{\n \t\t//Register services\n \t\tservices.AddSapphireDb(new SapphireDatabaseOptions(Configuration.GetSection("SapphireDb")));\n \t}\n } \f:(json:ExampleJSON.json) {\n \t"SapphireDb": {\n \t\t"ApiConfigurations": [\n \t\t\t{\n \t\t\t\t"Secret": "F6249E39DD6FBF6AA29D1D943390288392E6A819DC17FA057934EC3D48EAC06A06DE51B6DF6DBCD0BA8049C13B151EC71DEE0AD20C9E74237B8990D997E35968",\n \t\t\t\t"Key": "webapp",\n \t\t\t\t"Name": "Example Web Client"\n \t\t\t}\n \t\t]\n \t}\n }
The secret has to be stored as SHA512-hash.

You can create a hash here:

CanExecuteCommand

Checks if a connection is allowed to execute a command. Because every action is a command, this method can be used to generally control all interactions.
Default: (command, context) => true
Default (strict): (command, context) => context.User.Identity.IsAuthenticated

IsAllowedToSendMessages

Control if the user is allowed to publish messages.
Default: (context) => true
Default (strict): (context) => context.User.Identity.IsAuthenticated

WebsocketInterface

Enable websocket interface for connections.
Default: true

ServerSentEventsInterface

Enable SSE interface for connections.
Default: true

PollInterface

Enable polling (long polling) interface for connections.
Default: true

RestInterface

Enable rest interface for connections. Always enabled when using long polling or SSE
Default: true

This website uses Google Analytics. If you want to disable it just unselect the option: