I'm using Firebase authentication for my existing web API created on ASP.NET Core 3.1. I have to verify firebase user id token inside GetUserId
method of IUserIdProvider
interface.
Server Side Codes:
public class CustomUserIdProvider : IUserIdProvider
{
public string GetUserId(HubConnectionContext connection)
{
/* Getting token from header when a SignalR client is connecting */
string FirebaseUserIDToken = connection.GetHttpContext().Request.Headers["token"];
/* Decrypting firebase id token */
FirebaseToken firebaseToken = await FirebaseAuth.DefaultInstance.VerifyIdTokenAsync(token);
/* assigning firebase auth user id to SignalR user */
return firebaseToken.Uid;
}
}
the problem is await FirebaseAuth.DefaultInstance.VerifyIdTokenAsync(token)
is Asynchronous function and GetUserId
does not support Asynchronous calls.
Client Side Codes:
hubConnection = HubConnectionBuilder.create("<my server>/testHub").withHeader("token", <firebase id token>).build();
For security reasons I can not simply attached firebase UID in the header instead of firebase id token.