How can I use Google Cloud Task REST API from an external back-end server using Service Account?

Viewed 23

I have some problem using Google Cloud Task REST API from an external low-code server using Node.js but without having access to install local files, so I cannot use npm to install Google Cloud SDK. I hope someone can help me.

I'm trying to do a simple request, GET Task, but each time the response is "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project." I don't understand because i'm able to create a task via my Google Cloud Function that require authentification but the same token does not seems to work with Cloud Task.

Here is the call I've done :

Method : GET
url : https://cloudtasks.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION/queues/QUEUE_NAME/tasks/TASK_ID

header : {     
Authorization: Bearer MYTOKEN
}

Here is the claim of my token :

{ 
   alg: "RS256",
   typ: "JWT" 
}

{ 
   iss: SERVICE_ACCOUNT_EMAIL
   sub: SERVICE_ACCOUNT_EMAIL
   iat: Math.floor(new Date().getTime() / 1000);
   exp: iat + 3600;
   aud: "https://www.googleapis.com/oauth2/v4/token"
   target_audiance: (I've tried both "https://cloudtasks.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION/queues/QUEUE_NAME/tasks" and "https://cloudtasks.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION/queues/QUEUE_NAME/tasks/TASK_ID")
}

My service account principle

  • Cloud Functions Invoker
  • Cloud Tasks Viewer
0 Answers
Related