ClientException "failed to parse header value" when using Googleapis_auth package with flutter

1,444

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

Share:
1,444
SetNameHere
Author by

SetNameHere

Updated on December 21, 2022

Comments

  • SetNameHere
    SetNameHere over 1 year

    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.

  • SetNameHere
    SetNameHere almost 4 years
    thanks for your response. But yes I have granted the "Cloud Functions-Invoker" role to the used service account.
  • SetNameHere
    SetNameHere almost 4 years
    please see edit. I hope it helps and it is what you meant.
  • Juancki
    Juancki almost 4 years
    No, this wasn't. I mean't the full error that is alongside Failed to parse header value
  • SetNameHere
    SetNameHere almost 4 years
    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.
  • Juancki
    Juancki almost 4 years
    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
  • SetNameHere
    SetNameHere almost 4 years
    So I've talked to one of your collegues. On GCP side, it all seems to be configured correctly. Issue should be within flutter code.