I am using @microsoft/signalr package installed in Angular 11 application. I am getting 401 error once the access token got expired after 1 hour. Is there a way to get access token renewed after the token expiration something like by using refresh token in Angular 11?
signalr.service.ts:
import * as signalR from '@microsoft/signalr';
orderMessages: Subject<any> = new Subject();
saleMessages: Subject<any> = new Subject();
private getConnectionInfo(): Observable<SignalRConnectionInfo> {
return this.http.get<SignalRConnectionInfo>('http://localhost:7071/api/SignalRNegotiationFunction');
}
init() {
this.getConnectionInfo().subscribe(info => {
let options = {
accessTokenFactory: () => info.accessToken
};
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(info.url, options)
.withAutomaticReconnect([0, 1000, 5000, null])
.configureLogging(signalR.LogLevel.Information)
.build();
this.hubConnection.start().catch(err => console.error(err.toString()));
this.hubConnection.off('notifyresult');
this.hubConnection.on('notifyresult', (data: any) => {
if(data == "Orders") {
this.orderMessages.next(data);
}
else {
this.saleMessages.next(data);
}
});
});
}
Azure Function:
public static class SignalRNegotiationFunction
{
[FunctionName("SignalRNegotiationFunction")]
public static SignalRConnectionInfo Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
[SignalRConnectionInfo(HubName = "notification")] SignalRConnectionInfo connectionInfo)
{
return connectionInfo;
}
}