Firebase Admin : getUser isn't working while verifyIdToken works
Asked Answered
K

0

8

I'm initializing the firebase config as following,

firebaseAdmin.initializeApp({
  credential: applicationDefault(),
  projectId: "${my_project_id}",
});

Verify ID token is working,

firebaseAdmin
    .app()
    .auth()
    .verifyIdToken(idToken)
    .then((decodedIDToken) => {
      console.log("decodedIDToken: ", decodedIDToken);
    })
    .catch((error) => {
      console.log("error: ", error);
    })

But getUser is throwing error,

firebaseAdmin
      .app()
      .auth()
      .getUser(uuid)
      .then((data) => {
        console.log("user: ", data);
      })
      .catch((error) => {
        console.log("error: ", error);
      });

Error

errorInfo: {
    code: 'auth/internal-error',
    message: '//cloud.google.com/docs/authentication/adc-troubleshooting/user-creds . Raw server response: "{"error":{"code":403,"message":"Your application is authenticating by using local Application Default Credentials. The identitytoolkit.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .","errors":[{"message":"Your application is authenticating by using local Application Default Credentials. The identitytoolkit.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .","domain":"usageLimits","reason":"accessNotConfigured","extendedHelp":"https://console.developers.google.com"}],"status":"PERMISSION_DENIED","details":[{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"SERVICE_DISABLED","domain":"googleapis.com","metadata":{"service":"identitytoolkit.googleapis.com","consumer":"projects/${some_project_ID"}}]}}"'
  },
  codePrefix: 'auth'
}

I've ensured to set the correct project to both application-default and default project by running these,

$ gcloud auth application-default set-quota-project ${some_different project}
$ gcloud config set project ${my_project_id}

I've also confirmed both the projects have Identity Toolkit API enabled. enter image description here

Kerplunk answered 10/8, 2023 at 21:36 Comment(2)
I was able to unblock myself changing app authentication to use a service key instead of application default credentials. While this works, this is hardly an ideal solution.Kerplunk
I'm having the same issue, right now I'm making sure I run it on a server to work, but extremely not ideal.Flaherty

© 2022 - 2025 — McMap. All rights reserved.