Search code examples
google-cloud-pubsubgoogle-cloud-pubsublite

Retrieve PubSub Schema from external IP address with API Key


  1. I have created a PubSub schema

  2. I have created an API key with no restrictions

  3. I wish to cURL/Get this schema from an address outside of GCP

  4. I tried the below request but it's denied as per below

    me@J-5CG2200NLY:~/go/$ curl https://pubsub.googleapis.com/v1/projects/myprojetc199/schemas/pbschema_1?key=mylongkeyxxxxxxxxxxxx { "error": { "code": 403, "message": "User not authorized to perform this action.", "status": "PERMISSION_DENIED" } } How can I authenticate my request?

Thanks in advance


Solution

  • Pub/Sub does not support the use of API keys as an authentication method (as noted in the documentation). API keys are used for quota attribution for requests. You would have to use one of the alternative authentication methods like OAuth in order to retrieve the schema via a cURL/Get.

    If you are logged in via gcloud on an account that has permission to get schemas, you can then get the access token:

    gcloud auth application-default print-access-token
    

    Now, you can use that access token in a curl command:

    PROJECT=my-project
    SCHEMA=my-schema
    ACCESS_TOKEN=<token printed out above>
    curl -H "Authorization: Bearer $ACCESS_TOKEN" -X GET  https://pubsub.googleapis.com/v1/projects/$PROJECT/schemas/$SCHEMA