Ingo Manthey

Ingo Manthey

  • NA
  • 52
  • 5.7k

SignalR authorization, Angular, ASP.NET Core

Jan 25 2020 7:51 PM
Hello,
In my app I use IdentityServer4 for my web API. Now I want to use SignalR but I always get error 401. With my other http.get <T> calls I have no problems.
  1. [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme)]  
  2. public class ChatHub : Hub  
In the Angular Service I initialize the hub as follows.
  1. const tokenValue = '?token=' + this.authService.accessToken;  
  2. const hubUrl = `${this.configurations.baseUrl + '/hubs/chat?'}looney${tokenValue}`;  
  3.   
  4. this.hubConnection = new signalR.HubConnectionBuilder().withUrl(hubUrl).configureLogging(signalR.LogLevel.Information).build();  
 For the other http.get I set the request headers as follows:
  1. protected get requestHeaders(): { headers: HttpHeaders | { [header: string]: string | string[]; } } {  
  2.     const headers = new HttpHeaders({  
  3.       Authorization: 'Bearer ' + this.authService.accessToken,  
  4.       'Content-Type''application/json',  
  5.       Accept: 'application/json, text/plain, */*'  
  6.     });  
  7.   
  8.     return { headers };  
  9. }  
Can someone help me here??
Thanks in advance for any advice or tip 
 
 

Answers (1)