Q:

Keeping authentication state between Firebase - WebApp (.NET Core MVC)

I am creating an ASP.NET Core MVC app, where the authentication provider will be FireBase.
My Web App is hosted in Azure and, once user signs in, it sends an HTTPS request to my firebase endpoint, which looks like https://myFirebaseApp.cloudfunctions.net/signup with username and password, and it will create a user as below;
https://firebase.google.com/docs/auth/web/start?authuser=0
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

My intention is to get a kind of session token in the response and save it in a cookie. And everytime user navigates to another page, I will need to validate that cookie/token to keep authentication persistent.
What would be the way to achieve this? Or is there any better practice to keep this integration?

A:

I found out I can use custom tokens for this. What I need to use is createCustomToken and 
signInWithCustomToken methods.
https://firebase.google.com/docs/auth/admin/create-custom-tokens
Create Token:
  createCustomToken(request, response) {
    let uid = request.query.uid;
    if (!uid) {
      response.send("query.uid is required.");
      return;
    }
    let additionalClaims = {
      myExtraField: 1
    };
    this.admin
      .auth()
      .createCustomToken(uid, additionalClaims)
      .then(function(customToken) {
        // Send token back to client
        response.send(customToken);
      })
      .catch(function(error) {
        response.send(error);
      });
  }

Sign-in:
  signInWithCustomToken(request, response) {
    const id_token = request.query.id_token;
    if (!id_token) {
      response.send("query.id_token is required.");
      return;
    }

    // Sign in with signInWithCustomToken.
    this.authService
      .signInWithCustomToken(id_token)
      .then(result => {
        response.send(result);
      })
      .catch(error => {
        response.send(error);
      });
  }

