I've checked the other stacks about this but still not sure why i'm getting insufficient permissions error. Probably I'm being insecure.
I'm trying to sync users from 2 different firebase accounts. The first account calls a firebase function on the second account. If a user does not exist, it creates and does some databasing. If user exists, then it creates a custom token and passes it back to the first account to use in an iframe query parameter.
I've created IAM service account, created keys and saved to file, and edited the service token permissions like the other stacks explain but i'm getting the error nonetheless. Here's my function start:
const firebaseConfig = {
credential: admin.credential.applicationDefault(),
apiKey: "xxxxxxxxxxxxxxxxxxxxxxx",
authDomain: "itsli7-87384.firebaseapp.com",
databaseURL: "https://itsli7-87384.firebaseio.com",
projectId: "itsli7-87384",
storageBucket: "itsli7-87384.appspot.com",
messagingSenderId: "503897448704",
appId: "1:503897448704:web:45773bfb231a24bbe213e5"
}
fb.initializeApp(firebaseConfig);
admin.initializeApp(firebaseConfig);
And the function is running this.
return admin.auth().getUser(data.user.uid)
.then(async function () {
return admin.auth().createCustomToken(data.user.uid)
.then(function (customToken) {
res.send(customToken);
})
.catch(function (error) {
console.log('Error creating custom token:', error);
});
The error
code: auth/insufficient-permission
Error creating custom token: FirebaseAuthError: The caller does not have permission; Please refer to https://firebase.google.com/docs/auth/admin/create-custom-tokens for more details on how to use and troubleshoot this feature.