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

feat(samples): auth samples #1444

Merged
merged 13 commits into from
Sep 29, 2022
Merged

Conversation

FrodoTheTrue
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@FrodoTheTrue FrodoTheTrue requested review from a team as code owners August 22, 2022 19:43
@snippet-bot
Copy link

snippet-bot bot commented Aug 22, 2022

Here is the summary of changes.

You are about to add 6 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added size: l Pull request size is large. samples Issues that are directly related to samples. labels Aug 22, 2022
Copy link
Contributor

@piaxc piaxc left a comment

Choose a reason for hiding this comment

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

Thanks FrodoTheTrue! Some comments for you on the comments.

samples/authenticateImplicitWithAdc.js Outdated Show resolved Hide resolved
samples/authenticateImplicitWithAdc.js Outdated Show resolved Hide resolved
samples/authenticateExplicit.js Outdated Show resolved Hide resolved
* Uses a service account (SA1) to impersonate as another service account (SA2) and obtain id token for the impersonated account.
* To obtain token for SA2, SA1 should have the "roles/iam.serviceAccountTokenCreator" permission on SA2.
*
* @param {string} scope - The scope that you might need to request to access Google APIs,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is all outside of the region tags. Wouldn't we want users to be able to see it from the docs?

samples/idTokenFromImpersonatedCredentials.js Outdated Show resolved Hide resolved
samples/idTokenFromImpersonatedCredentials.js Outdated Show resolved Hide resolved
* @param {string} url - The url or target audience to obtain the ID token for.
*/
function main(url) {
// [START auth_cloud_idtoken_metadata_server]
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, please include the comments in the region tag

samples/idTokenFromMetadataServer.js Outdated Show resolved Hide resolved
samples/idTokenFromMetadataServer.js Outdated Show resolved Hide resolved
samples/idTokenFromMetadataServer.js Outdated Show resolved Hide resolved
* @param {string} targetAudience - The url or target audience to obtain the ID token for.
*/
function main(targetAudience, jsonCredentialsPath) {
// [START auth_cloud_idtoken_service_account]
Copy link

Choose a reason for hiding this comment

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

Can we move the region tag to line 14 to include the comment above?

* logical identifier of an API service, such as "iap.googleapis.com".
*/
function main(idToken, expectedAudience) {
// [START auth_cloud_verify_google_idtoken]
Copy link

Choose a reason for hiding this comment

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

Same comment here.

@FrodoTheTrue
Copy link
Contributor Author

Hi @piaxc @Sita04, thanks for the review, just sent the updates

Regarding moving comments for variables - unfortunately everywhere in js (and in Go) samples we have this structure, so user can jump directly to the github code if it is really needed. I moved important comments to the region tags, but for variables I prefer to keep the structure consistent with other languages.

@FrodoTheTrue
Copy link
Contributor Author

@bcoe could you please help with reviewing this from node.js side?

@bcoe bcoe added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Sep 13, 2022
samples/authenticateExplicit.js Show resolved Hide resolved
samples/authenticateExplicit.js Show resolved Hide resolved
samples/authenticateExplicit.js Show resolved Hide resolved
samples/authenticateExplicit.js Outdated Show resolved Hide resolved
samples/authenticateImplicitWithAdc.js Show resolved Hide resolved
samples/idTokenFromMetadataServer.js Show resolved Hide resolved
samples/idTokenFromServiceAccount.js Show resolved Hide resolved
samples/test/auth.test.js Outdated Show resolved Hide resolved
samples/verifyGoogleIdToken.js Outdated Show resolved Hide resolved
samples/verifyGoogleIdToken.js Show resolved Hide resolved
@danielbankhead danielbankhead self-assigned this Sep 14, 2022
@piaxc
Copy link
Contributor

piaxc commented Sep 14, 2022 via email

@FrodoTheTrue
Copy link
Contributor Author

@danielbankhead thanks a lot for the review! updated the PR

also we have already published canonical samples for Java (and Python): https://github.com/googleapis/google-auth-library-java/tree/main/samples/snippets/src/main/java, so most of the ideas and comments moved here (I commented)

@FrodoTheTrue
Copy link
Contributor Author

I just moved the same code: GoogleCloudPlatform/nodejs-docs-samples#2759
@danielbankhead could you please also approve? really appreciate

@danielbankhead
Copy link
Contributor

I just moved the same code: GoogleCloudPlatform/nodejs-docs-samples#2759
@danielbankhead could you please also approve? really appreciate

I like these here for integration purposes, say an unexpected breaking change was made in the codebase, having them here would make it easy to catch in a PR rather than in another repo. In either case, approved.

@FrodoTheTrue FrodoTheTrue added the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 29, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 29, 2022
@bcoe bcoe removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Sep 29, 2022
@bcoe
Copy link
Contributor

bcoe commented Sep 29, 2022

defer to @danielbankhead's review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants