0
votes

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.

  1. 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());
    
  2. 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.

1
I have the same issue right now with the linux container. Did you get a solution for it? - Marzouk

1 Answers

0
votes

You have to initialize the SDK by creating a new FirebaseApp first. See the code samples in https://firebase.google.com/docs/admin/setup