Marcin
Marcin

Reputation: 1203

Google Cloud Scheduler - HTTP headers not respected

I'm trying to send push to my app using Google Cloud Scheduler:

gcloud beta scheduler jobs create http PUSH --schedule="0 * * * *" --uri="https://fcm.googleapis.com/fcm/send" --description="desc" --headers="Authorization: key=<AUTHKEY> --http-method="POST" --message-body="{\"to\":\"/topics/allDevices\",\"priority\":\"low\",\"data\":{\"success\":\"ok\"}}"    

The result is always 401 Unauthorized. After issuing command:

gcloud beta scheduler jobs describe PUSH

I do not get these headers back:

description: desc
httpTarget:
  body: eyJ0byI6Ii90b3BpY3MvYWxsnByaW9yaXR5IjoRGV2aWNlcyIsIiaGlnaCIsImRhdGEiOnsic3VjY2VzcyI6Im9rIn19  <--- THIS IS WEIRD
  headers:
    Content-Type: application/octet-stream
    User-Agent: Google-Cloud-Scheduler
  httpMethod: POST
  uri: https://fcm.googleapis.com/fcm/send
lastAttemptTime: '2018-11-07T20:32:37.657408Z'
name: projects/..../locations/europe-west1/jobs/PUSH
retryConfig:
  maxBackoffDuration: 3600s
  maxDoublings: 16
  maxRetryDuration: 0s
  minBackoffDuration: 5s
schedule: 0 * * * *
scheduleTime: '2018-11-07T21:00:00.681498Z'
state: ENABLED
status:
  code: 16
timeZone: Etc/UTC
userUpdateTime: '2018-11-07T20:29:15Z'

Upvotes: 3

Views: 3454

Answers (1)

John Hanley
John Hanley

Reputation: 81454

The first question about body:

body:eyJ0byI6Ii90b3BpY3MvYWxsnByaW9yaXR5IjoRGV2aWNlcyIsIiaGlnaCIsImRhdGEiOnsic3VjY2VzcyI6Im9rIn19 <--- THIS IS WEIRD

This is the base64 encoding of

{\"to\":\"/topics/allDevices\",\"priority\":\"low\",\"data\":{\"success\":\"ok\"}}

Google is taking your --message-body and encoding it in base64.

Next regarding the header issue. You have a several errors in your '--headers`.

--headers="Authorization: key=AUTHKEY

You are missing a quote mark after AUTHKEY. I will assume that this issue is just editing mistake creating the question. (Note I could not figure out how to include the less-than and greater-than characters in this response).

However, the syntax for --headers is wrong. The --headers expects KEY=VALUE, not KEY:VALUE. In this example the KEY is Authorization and the VALUE is key=AUTHKEY.

--headers="Authorization=key=AUTHKEY"

Upvotes: 5

Related Questions