GoogleCloudPlatform / GoogleCloudPlatform/php-docs-samples

[Pub/Sub]: add sample for decoding and verifying JWT from Pub/Sub

Open
#1,243 0 comments 5 reactions 0 assignees View on GitHub
api: pubsub samples type: feature request
Dominant language
PHP
Stars
1k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Please add a sample in [this](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine) directory and show how to **decode** and **verify** a JWT included in the header of a Pub/Sub push message (when authenticated push is enabled). The other language (Go, Node.js, Java, Python) samples already [exist](https://cloud.google.com/pubsub/docs/push#authentication_and_authorization_by_the_push_endpoint). This sample will be used alongside those.

I'm not sure if PHP has a cloud client library for this task (please find out if you can), but it appears to have an API client library [`google-api-php-client`](https://github.com/googleapis/google-api-php-client) that does the job, specifically, the [`verifyIdToken()`](https://github.com/googleapis/google-api-php-client/blob/81696e6206322e38c643cfcc96c4494ccfef8a32/src/AccessToken/Verify.php#L88) method.

You can use Google's public keys referenced [here](https://developers.google.com/assistant/identity/google-sign-in#access_profile_information_in_your_backend) to verify JWTs from the real Pub/Sub service. For writing tests, you can use mocked public keys in other language samples.

You can use the region tag `gaeflex_net_pubsub_auth_push` for this sample.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.