SetNameHere
SetNameHere

Reputation: 121

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

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.

Upvotes: 4

Views: 4434

Answers (1)

Juancki
Juancki

Reputation: 1872

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

Upvotes: 3

Related Questions