I have an ionic/angular frontend where I have the user registration via firebase. I already retrieve my firebase token, send it to my .net backend and verify the token with the [Authorize] annotation.
After authorization, I want to decode the token and use the id of the user for further processing.
Step get the token from the "Authorization" header
string authHeader = this.HttpContext.Request.Headers["Authorization"]; var decodedFirebaseToken = await fireBaseAuthenticationHelper.GetUserFromFirebaseIdAsync(authHeader.Substring("Bearer ".Length).Trim());Step retrieve the decoded token
public async Task<FirebaseToken> GetUserFromFirebaseIdAsync(string token) { FirebaseToken decodedToken = await FirebaseAuth.DefaultInstance .VerifyIdTokenAsync(token); return decodedToken; }
The problem now is that the FirebaseAuth.DefaultInstance is always null and throws a null pointer exception. I don't know where or how to initialize the DefaultInstance. On the FirebaseAuth class is a comment:
public sealed class FirebaseAuth : IFirebaseService
{
//
// Summary:
// Gets the auth instance associated with the default Firebase app. This property
// is null if the default app doesn't yet exist.
public static FirebaseAuth DefaultInstance { get; }
So I am pretty sure I have to initialize it somewhere but I can't find where.