SapphireDb logo SapphireDb

Server setup - Authentication

SapphireDb allows to control permissions for specific operations with different mechanisms.

Setup

You have to configure your application to use identity or some other way of authentication. SapphireDb relies on the auth-mechanisms if Identity. After you have configured Identity you have to do a small adjustment to make SapphireDb work with that.

\f:(csharp:Startup.cs) public class Startup\n {\n \tpublic void ConfigureServices(IServiceCollection services)\n \t{\n \t\tservices.AddAuthentication(cfg =>\n \t\t{\n \t\t\tcfg.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;\n \t\t\tcfg.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;\n \t\t}).AddJwtBearer(cfg =>\n \t\t{\n \t\t\tcfg.TokenValidationParameters = jwtOptions.TokenValidationParameters;\n \t\t\tcfg.Events = new JwtBearerEvents()\n \t\t\t{\n \t\t\t\tOnAuthenticationFailed = ctx =>\n \t\t\t\t{\n \t\t\t\t\tctx.Response.StatusCode = StatusCodes.Status401Unauthorized;\n \t\t\t\t\treturn Task.CompletedTask;\n \t\t\t\t},\n \t\t\t\tOnMessageReceived = ctx =>\n \t\t\t\t{\n \t\t\t\t\t//Read the authentication token from query because js-websocket cannot send token as header\n \t\t\t\t\tstring authorizationToken = ctx.Request.Query["authorization"];\n \t\t\t\t\tif (!string.IsNullOrEmpty(authorizationToken))\n \t\t\t\t\t{\n \t\t\t\t\t\tctx.Token = authorizationToken;\n \t\t\t\t\t}\n\n \t\t\t\t\treturn Task.CompletedTask;\n \t\t\t\t}\n \t\t\t};\n \t\t});\n \t}\n\n \tpublic void Configure(IApplicationBuilder app, IWebHostEnvironment env)\n \t{\n \t\tapp.UseAuthentication();\n \t}\n }

Access user details

To access the details of a user you can use the default methods provided by identity.
Whenever you get an instance of HttpInformation you can access the user details by accessing HttpInformation.User

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