SrtsNetLayer 0.1.8
dotnet add package SrtsNetLayer --version 0.1.8
NuGet\Install-Package SrtsNetLayer -Version 0.1.8
<PackageReference Include="SrtsNetLayer" Version="0.1.8" />
<PackageVersion Include="SrtsNetLayer" Version="0.1.8" />
<PackageReference Include="SrtsNetLayer" />
paket add SrtsNetLayer --version 0.1.8
#r "nuget: SrtsNetLayer, 0.1.8"
#addin nuget:?package=SrtsNetLayer&version=0.1.8
#tool nuget:?package=SrtsNetLayer&version=0.1.8
SignalR TypeScript Interface Network Layer
Based on SignalR Core
Authentication and Authorization
With the SrTs-NetLayer the connection is authenticated and the authentication result stored on the server through the connection object, like a session. It is not necessary to tell the client any resulting information or session ids. Since a connection has to be re-authenticated after an intermittent disconnect and the subsequent reconnect, it is convenient to have the client persist enough information to restore the session on a reconnect, like a session token or a JWT.
Authentication
With SrTsNetLayer there are two main ways to authenticate a connection ...
Authentication through SignalR
use setAuth(bearerToken) or Component.props.BearerAuth with default SignalR auth
The connection will be authenticated while being established and no boundaries can be called without being authenticated. An IConnectionMiddleware can be implemented much to the same effect.
- Caveat: As detailed in the docs, when using websockets the bearer token is sent as an url query parameter
- Caveat: Setting/Refreshing the token while the connection is alive has no effect
- Caveat: Aside from the IConnectionMiddleware, this is not well implemented yet and untested
Authentication through NetLayer
LoginBoundary, setConnectionParameters
- Caveat: Since auth happens after connections initialization Context.User is unavailable
Use the extension functions Context.SetNetLayerUser and Context.GetNetLayerUser instead. These will set the data on the connection using Context.Items - Caveat: Context.UserIdentifier (through IUserIdProvider) cannot use Context.User principal
Since connections are supposed to be long lived, NetLayerAuth is preferred
Authorization
The AuthorizeAttribute is not yet available four BoundaryMethods
The Authorize Attribute required middlewares:
- NetLayerAuthorizationMiddleware ??
Sample usage
public void ConfigureServices(IServiceCollection services) {
services.AddCors();
services.AddSrTsNetLayer(options => { });
services.AddBoundariesFromAssemblyScan(GetType().Assembly);
// Alternativley add them manually
// services.AddSingleton<IBoundarySupplier, ProxyBoundarySupplier>();
// services.AddBoundary<SomeBoundary>();
// ...
var jsonOptions = new JsonSerializerOptions() {
WriteIndented = false,
DictionaryKeyPolicy = null,
IncludeFields = false,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
UnknownTypeHandling = JsonUnknownTypeHandling.JsonElement,
PropertyNameCaseInsensitive = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
// for MemberCasing.PascalCase during generation
PropertyNamingPolicy = null;
// for MemberCasing.JavascriptCamelCase during generation
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
jsonOptions.Converters.Add(new JsonStringEnumConverter());
jsonOptions.Converters.Add(new TimespanConverter());
services.AddSingleton(jsonOptions);
services.AddSignalR(options => { options.EnableDetailedErrors = false; }).AddJsonProtocol(options => {
options.PayloadSerializerOptions = jsonOptions;
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseWebSockets(new WebSocketOptions {
KeepAliveInterval = TimeSpan.FromSeconds(120),
// For development
AllowedOrigins = { "http://localhost:1234", $"http://{Environment.MachineName}:1234", "http://localhost:8080", $"http://{Environment.MachineName}:8080",
// For production
"http://localhost:80", $"http://{Environment.MachineName}:80", "https://localhost:443", $"https://{Environment.MachineName}:443" },
});
app.UseSrTsNetLayer()
.AddConnectionMiddleware<ConnectionTimerMiddleware>()
.AddBroadcastMiddleware<DefaultBroadcastMiddleware>()
.AddRequestMiddleware<RequestTimingMiddleware>()
#if DEBUG
.AddRequestMiddleware<DeveloperExceptionMiddleware>()
#endif
.AddRequestMiddleware<EndpointRoutingMiddleware>()
.AddRequestMiddleware<AuthorizationMiddleware>()
.AddRequestMiddleware<RequestEndpointMiddleware>()
;
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.AspNetCore.SignalR.Common (>= 9.0.2)
- Neco.Common (>= 0.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.