dotnet / dotnet/AspNetCore.Docs
Connect to hub - missing JWT guidance
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 97
Description
The example in this page showing the hub connection only requiring two methods (.WithUrl() & .Build()) appears to be incomplete. The Azure SignalR Service requires an authenticated session however there is no mention of this. I found the correct guidance from the link below:
SignalR binding example: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-signalr-service#signalr-connection-info-input-binding
I was able to get this working by setting up a web API to handle the "/negotiate" endpoint as an Azure Function. In my case I didn't have a specific user I needed to authenticate so the GitHub code sample from the link below wasn't helpful; even if it did give me a hint to this requirement.
https://github.com/aspnet/AzureSignalR-samples/blob/master/samples/Serverless/ClientHandler.cs#L25
My example:
```
SignalRConnectionInfo signalRConnectionInfo;
signalRConnectionInfo = await GetSignalRJwt();
hubConnection = new HubConnectionBuilder()
.WithUrl(signalRConnectionInfo.Url, options =>
{
options.AccessTokenProvider = () => Task.FromResult(signalRConnectionInfo.AccessToken);
})
.Build();
```
---
#### Document Details
⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*
* ID: c9bc1072-be2c-94f6-49bf-daa9e97dff2d
* Version Independent ID: 36052173-7061-6d01-8aed-915685cd7cf6
* Content: [ASP.NET Core SignalR .NET Client](https://docs.microsoft.com/en-us/aspnet/core/signalr/dotnet-client?view=aspnetcore-3.0&tabs=visual-studio#additional-resources)
* Content Source: [aspnetcore/signalr/dotnet-client.md](https://github.com/aspnet/AspNetCore.Docs/blob/master/aspnetcore/signalr/dotnet-client.md)
* Product: **aspnet-core**
* Technology: **aspnetcore-signalr**
* GitHub Login: @bradygaster
* Microsoft Alias: **bradyg**
Contributor guide
Assessment
This issue has not been assessed yet.