I'm struggling with getting the user id token included in the call to httpsCallable(). I call it like this from flutter:
Future<bool> cfCreateAccount(String name, address, email, phoneNumber, password, randomSalt, {int? parentId}) async {
HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('createAccount', options: HttpsCallableOptions(timeout: Duration(seconds: 10)));
try {
var param = {'name': name, 'address': address, 'email': email, 'phone_number': phoneNumber, 'password': password, 'random_salt': randomSalt};
final HttpsCallableResult result = await callable.call(param);
if (result.data['response'] == 'Pass') {
return true;
}
} catch (e) {
print("Failed Cloud Function Call: $e");
}
return false;
}
This person was asking I think a similar question but for them they said the answer was Authorization was automatically included:
How to add headers to firebase httpscallable
I've signed in in my Flutter app with this:
await auth.signInWithEmailAndPassword(email: user, password: password);
and afterwards I can call user.getIdToken() and it shows what looks like my auth id. But every way I try to check seems to indicate that the auth header isn't in the request to the cloud function.
I wrote the cloud function in python. It looks like this:
def createAccount(request):
request_json = request.get_json(silent=True)
request_args = request.args
sql = None
conn = None
res = dict()
res['data'] = str(request.authorization)
return json.dumps(res)
But this returns "None". Meaning there is no authorization in the request. I also tried this but it gives an error in python:
token = request.headers['Authorization'].replace('Bearer ','')
Is there some issue maybe with how I call httpsCallable() in flutter? I'm not sure how FirebaseFunctions.instance.httpsCallable() gets the auth id from FirebaseAuth.instance ??
Here is the cloud function on the Firebase console, just to show that it is there and in python3.8: