Robin Cordemans avatar image
Robin Cordemans asked

Getting 401 when connecting to SignalR


I am using Unity, we are making a multiplayer VR game with a lobby system.

Polling the data from lobbies is too slow for our use case, so we want to speed this up.

After some research SignalR seems to be the way to go.

We can't use ASP.NET because not only does this not seem to work with Unity, NuGet packages generally break cross platform portability in Unity, there is no asset or package that adds support for ASP.NET to Unity, nor do we have time to make our own.

Instead, we are using an asset from the Unity asset store called Best HTTP/2, which has everything ASP.NET has including the HubConnection.

I can successfully get the server url and access token from the negotiate rest API, which I assume I have to use in the HubConnection. According to the PlayFab documentation, the token must be passed through the header. The asset we use is a little different from ASP.NET as it uses interfaces for authorization and such. But I wrote a custom authorization script that passes the token to the header.

The problem is I cannot find which key to use for the token, since the header uses key value pairs. I've tried X-SecretKey, X-AccessToken, AccessToken, etc and all I get when trying to connect is the following error:

Negotiation Request Finished Successfully, but the server sent an error. Status Code: 401- Message:

The empty message doesn't help either.

Am I doing something wrong or is there a very specific key for this access token?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rick Chen avatar image Rick Chen ♦ commented ·

Generally, the http 401 error means you are not authorized to call the API. Which API were you calling and what document were you referring to?

0 Likes 0 ·
Robin Cordemans avatar image Robin Cordemans Rick Chen ♦ commented ·

I'm simply creating a HubConnection with the url and token returned from the negotiate api, and then calling ConnectAsync() on the HubConnection. This is what returns the 401 error.

0 Likes 0 ·

0 Answers


Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]