I have an angular application that connects to Net Core through SignalR to get info. Locally works perfectly but when the application is doing the request from Azure is throwing this error
WebSocket connection to 'wss://mysite.azurewebsites.net/notifications?id=someId&access_token=sometoken' failed: Error during WebSocket handshake: Unexpected response code: 302 Error: Failed to start the transport 'WebSockets': undefined
But is still returning the data and doing the connection and bringing the info, just annoying errors on console
this is my Angular Side call to signalR
private createConnection() {
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(`${this.libraryConfig.api.notification.baseUrl}/notifications`, { accessTokenFactory: () => this.access_token })
.build();
}
and this is my code on StartUp on Net Core
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = "https://sts.windows.net/tenat/v2.0";
options.Audience = Configuration.GetSection("AzureAd").GetSection("Audience").Value;
options.TokenValidationParameters.ValidateLifetime = true;
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
// If the request is for our hub...
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
(path.StartsWithSegments("/notifications")))
{
// Read the token out of the query string
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
});
Ive been trying every solution I could find but nothing works.
NOTE: Im using Azure Active Directory to sign in the client