Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service-to-service Node.js sample #1704

Closed
wants to merge 17 commits into from

Conversation

kelsk
Copy link
Contributor

@kelsk kelsk commented Apr 3, 2020

Refactored snippet from service-to-service guide

  • Replaced "request" (deprecated) with "got"

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Apr 3, 2020
@kelsk
Copy link
Contributor Author

kelsk commented Apr 3, 2020 via email

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@averikitsch averikitsch self-requested a review April 3, 2020 18:54
run/authentication/auth.js Outdated Show resolved Hide resolved
run/authentication/auth.js Outdated Show resolved Hide resolved
run/authentication/auth.js Outdated Show resolved Hide resolved
run/authentication/auth.js Show resolved Hide resolved
run/authentication/auth.js Outdated Show resolved Hide resolved
run/authentication/auth.js Outdated Show resolved Hide resolved
run/authentication/auth.js Outdated Show resolved Hide resolved
@averikitsch
Copy link
Contributor

You will also need to add a testing file similar to https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/.kokoro/run

@averikitsch averikitsch added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Apr 6, 2020
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Apr 6, 2020
@kelsk kelsk requested a review from averikitsch May 4, 2020 22:13
@kelsk kelsk marked this pull request as ready for review May 4, 2020 22:13
res = await requestServiceToken('');
});

it('should return an error if given invalid Receiving Service URL', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a test that passes. When running on kokoro a request to the metadata server should succeed. You could write a test that looks for the env var 'GCLOUD_PROJECT' but make a comment that it must be unset locally.

@averikitsch averikitsch requested a review from grayside May 5, 2020 15:54
Copy link
Collaborator

@grayside grayside left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is shaping up nicely, however it's worth noting that there will soon be a change in how we want to approach minting the identity token. Depending on timing this might be a change to this PR or a follow-up, I hope to have a clearer answer on that by EOD.

// See the License for the specific language governing permissions and
// limitations under the License.

const requestServiceToken = async (receivingServiceURL = 'https://SERVICE_NAME-HASH-run.app') => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow why this function exists? If we're running in an environment that can mint a token, let's write an integration test that mints the token. We can split the request function to something that returns the token from metadata so it can be tested without making an HTTP request, or we can keep this all in one but use request mocking to inspect and validate the token: https://github.com/sindresorhus/got#testing


let res;

describe('requestServiceToken tests', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some deeper test coverage: can we parse out the auth token and at least do basic validation that it's a proper JWT?

@grayside
Copy link
Collaborator

grayside commented May 8, 2020

The ID Token library changes came together in the last month, have been released, and the Yoshi team was kind enough to create a variant of the idtoken-iap sample for Cloud Run: https://github.com/googleapis/google-auth-library-nodejs/blob/master/samples/idtokens-cloudrun.js.

To avoid duplication of maintenance work and ensure the sample stays aligned with library changes, I think we should prefer using that sample.

Thank you for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no This human has *not* signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants