1

I am having trouble accessing user information from the Firebase Cloud Functions environment.

What I am trying to do.

const admin = require('firebase-admin') admin.initializeApp() exports.test = functions.https.onRequest(() => { admin.auth().getUser('<user_id>').then(user => { return console.log(user) }).catch(e => { console.error(e) }) }) 

Now, when I run the test function, I get the following error.

{ code: 'auth/insufficient-permission', message: 'Credential implementation provided to initializeApp() via the "credential" property has insufficient permission to access the requested resource. See https://firebase.google.com/docs/admin/setup for details on how to authenticate this SDK with appropriate permissions.' }, codePrefix: 'auth' } 

Now, my question is that if it is possible to use admin.auth().getUser from the cloud functions environment.

1 Answer 1

4

You need credentials file which you pass to admin sdk initialize function. Auth related task need this configuration in cloud functions.

Go to you Firebase Console -> Settings -> Project Settings -> Service Accounts -> Generate new private key.

Download the file and include in you code.

P.S: make sure this file is not shared to public in any form (add it to git ignore), since have this file gives full access to you firebase project.

Sign up to request clarification or add additional context in comments.

2 Comments

or you can just add Service Account Token Creator to your IAM credentials, firebase functions will automatically be a safe environment
Fail to see how this answers the question. I got this error whilst using a service account.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.