Technology, Continued...

Ramblings about business, technology, development and my life

NAVIGATION - SEARCH

Using bearer tokens with SignalR

I am using bearer tokens to authenticate my Angular app with my backend WebApi, well, API.  I am adding SignalR to the app, and could not get user.identity.name to resolve to the currently authenticated user when trying to retrieve it from the hub OnConnected method.  Long and short, I had forgotten to add the bearer token to the SignalR ajax requests.  The code to do so is below.

var accessToken = localStorage.getItem("accessToken");
$.signalR.ajaxDefaults.headers = { Authorization: "Bearer " + accessToken };


Once that was done and my startup.cs file was correctly set to use bearer tokens, I was good to go.

Comments are closed