I'm currently working on a project with a react client and asp.net server.
I was tryin to add authorization to the signalR requests in the server using the existing claims that the user use in the api but I couldn't wrap my head around it.
I managed to receive the access token from the client but I don't understand how I can receive Context.User.Claims.
I'm adding the client signalR connection and a try from the server:
client:
let newConnection = new HubConnectionBuilder()
.configureLogging(LogLevel.Debug)
.withUrl(`${URL}${HubUrl}?access_token=${'SampleAccessToken'}`, {
// a token factory for the server, not sure why we need it
// accessTokenFactory: () => 'SampleAccessToken',
skipNegotiation: true,
transport: HttpTransportType.WebSockets,
})
.build();
Server:
public async Task JoinJobGroup()
{
var httpContext = Context.GetHttpContext();
var tmp = httpContext.Request.Query["access_token"];
// TODO: Receive the claims form tmp or other solution
// TODO: Check if claim is valid for operation
await _Context.Groups.AddToGroupAsync(Context.ConnectionId, "JOB_GROUP_NAME");
}