refactor(examples): simplify auth examples and fix response buffering#4
refactor(examples): simplify auth examples and fix response buffering#4
Conversation
- Add env var validation in go-cli before calling the SDK - Eliminate duplicate userinfo network call in python-cli by threading result into print_token_info - Move credstore import to top level in python-cli - Stream and cap response body at source in python-m2m instead of buffering full response - Align scope order to profile/email consistently across all examples - Fix grammar in go-m2m env var error message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the language examples to reduce redundant network calls, improve upfront configuration validation, and bound HTTP response buffering when printing userinfo output.
Changes:
- Add early environment-variable validation in
go-cliand improve the env-var error grammar ingo-m2m. - Eliminate a duplicate
userinforequest inpython-cliby passing the already-fetched userinfo intoprint_token_info, and move the credstore import to the module level. - Update
python-m2mto stream the userinfo response body and cap output to 1 MB, and align scope ordering to["profile", "email"].
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python-m2m/main.py | Switches from resp.content buffering to streamed body reading with a size cap; aligns scope order. |
| python-cli/main.py | Avoids duplicate userinfo call by threading userinfo through print_token_info; moves credstore import to top-level; aligns scope order. |
| go-m2m/main.go | Fixes env-var error message grammar. |
| go-cli/main.go | Adds upfront env-var validation and uses the validated values when initializing the SDK client. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Replace bytes concatenation with bytearray.extend() to accumulate streamed chunks in O(n) instead of O(n²) - Skip empty chunks early and check remaining capacity before each extend to cap at MAX_BODY_SIZE+1 without a post-loop slice Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Change WithScopes("email", "profile") to WithScopes("profile", "email") for consistency with all other examples in this repo
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
go-cliwith a clear fatal message before calling the SDKuserinfonetwork call inpython-cliby threading the already-fetched result intoprint_token_info(one request instead of two on the happy path)credstoreimport to top level inpython-cli(was deferred inside exception handler)python-m2mresponse body read: use streamingiter_bytes()capped at MAX_BODY_SIZE+1 bytes instead of buffering the full response viaresp.content[profile, email]consistently across all examplesgo-m2menv var error messageTest plan
go-cli: run with missing env vars — expect clear fatal message and exitgo-cli: run with valid env vars — authenticate and print token info as beforepython-cli: verify single userinfo network call on happy path (no duplicate on cache hit)python-m2m: verify large response is capped at 1 MB and memory is bounded🤖 Generated with Claude Code