My question is pretty straightforward. I am using Windows Authentication in .NET Core. On the front end part of the app (Angular) I have a HTTP interceptor which sets widhcredentails: true to the all HTTP requests.
This interceptor does not work with WebSocket, so I need a solution for adding the same code from Interceptor to the SignalR service.
Here is my interceptor code:
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>>
{
request = request.clone({ withCredentials: true });
return next.handle(request);
}
And here is my SignalR service:
this.requestConnection = new HubConnectionBuilder().
withUrl(`${environment.apiUrl}/request`).
withAutomaticReconnect([0, 2000, 30000, 60000, null]).
build();
this.requestConnection.
start().
then(() => console.log('Connection started')).
catch(err => console.log(`Error while starting connection: ${err}`));
Keep in mind that interceptor is added in providers array in the app.module component :
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: WinAuthInterceptor,
multi: true
}
],
SignalR service is injected in the root.
@Injectable({
providedIn: 'root'
})