4

I'm trying to develop a flutter (web) application which needs to invoke access restricted http triggered cloud functions.

Therefore I have created a service account in my google cloud console and followed the example on how to retrieve an authenticated http client as an autonomous application of the googleapis_auth package (https://github.com/dart-lang/googleapis_auth).

final accountCredentials = new ServiceAccountCredentials.fromJson(r'''{ "private_key_id": "****", "private_key": "****", "client_email": "****.iam.gserviceaccount.com", "client_id": "****", "type": "service_account" }'''); 
var scopes = [CloudfunctionsApi.CloudPlatformScope]; 
AuthClient client = await clientViaServiceAccount(accountCredentials, scopes);

This seems to work fine. But when I try to use the received client to make a post request to my cloud function, I get a ClientException ("failed to parse header value").

http.Response resp = await client.post( CloudFunctiontriggerURL, body: {'data': userId});

As I understand the examples, this should work fine without specifying any headers manually in the POST function call. Correct? However, even if I specify the header manually, I get this error.

Any help with this would be highly appreciated.

1 Answer 1

3

I believe that you are getting 401 Unauthorized: "Failed to parse header value" exception.

In order to invoke a restricted http Cloud Functions, the service account need the cloudfunctions.functions.invoke permission which can be granted with the role roles/cloudfunctions.invoker. Please confirm this.

https://cloud.google.com/functions/docs/reference/iam/roles

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

6 Comments

thanks for your response. But yes I have granted the "Cloud Functions-Invoker" role to the used service account.
please see edit. I hope it helps and it is what you meant.
No, this wasn't. I mean't the full error that is alongside Failed to parse header value
Okay sorry. Could you tell me how to retrieve the required information? I have never needed this before and therefore I am still quite inexperienced with this.
I would suggest you to contact the Google Cloud Platform Support, with the project id and cloud function name that you need help with. cloud.google.com/support-hub
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.