Skip to content

Instantly share code, notes, and snippets.

@ThomasPe
Created January 9, 2024 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasPe/78bfef4aa6e0b2c4e5beef24178c0b78 to your computer and use it in GitHub Desktop.
Save ThomasPe/78bfef4aa6e0b2c4e5beef24178c0b78 to your computer and use it in GitHub Desktop.
SignalR Service Negotiation in C# ASP.NET Core
public async Task<NegotiationResponse> Negotiate(Guid userId, CancellationToken ct)
{
string connectionString = "Endpoint=https://myapp.service.signalr.net;AuthType=azure.msi;Version=1.0;"
ServiceManager serviceManager = new ServiceManagerBuilder()
.WithOptions(option =>
{
option.ServiceEndpoints =
[
new(connectionString)
];
})
.BuildServiceManager();
ServiceHubContext hubContext = await _serviceManager
.CreateHubContextAsync(_options.HubName, ct)
.ConfigureAwait(false);
NegotiationResponse response = await _hubContext.NegotiateAsync(
new NegotiationOptions()
{
UserId = userId.ToString(),
EnableDetailedErrors = _options.EnableDetailedErrors
}, ct)
.ConfigureAwait(false);
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment