I'm trying to learn SignalR and IdentitySever 4. I've created an application which consists of three services: A - Asp .net core MVC application; B - Identity server based on Identity Server 4; C - SignalR service with ChatHub. Application A and C used B as OpenIdConnect identity service. Authorization is required in Home Controller of Mvc application(A) and on ClientHub of Application C.
It should work in a next way:
- User open Mvc application(A).
- Then he is redirected to identity server(B) in order to log in.
- After login user is redirected to the home page of the MVC application and should be made a connection to the SignalR hub and there is a problem. Connection can't be made and it fails on Negotiate request, in the browser console I see only those errors that are not were informational: enter image description here
During the investigation, I've added also controller Home with Index action with authorization to SignalR service, which returns view where also a connection to hub should be made, and in this case, it works.
Added handlers for OpenIdConnectEvents and I see only OnRedirectToIdentityProvider event is raised. I read from https://docs.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-3.1 that if the user is logged in, the SignalR connection automatically inherits this authentication, maybe it is the problem that authentication used in MVc app is not valid for Hub. Can anyone help with advice, please?
Update As I can see an error from the console occurs because in case negotiate request is made server returns the login page (https://localhost:5001/connect/authorize?) which means cookies from MVC client are not valid for Hub: authorize request cancelled
Looks like OpenIdConnect here. Is there any way to authenticate users?