Fix auth failures when accounts.json registry is missing#175
Fix auth failures when accounts.json registry is missing#175jpoehnelt merged 1 commit intogoogleworkspace:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 6a5efcb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses critical authentication failures that occurred when the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses three related authentication bugs that led to API failures when an accounts.json registry was missing. The changes correctly adjust credential resolution to fall back to legacy credentials.enc, ensure openid and email scopes are always included during login for proper account registration, and improve error propagation so that real authentication failures are no longer silently ignored. The added tests provide good coverage for the new logic. I have one suggestion to make the error handling in main.rs more robust.
Note: Security Review did not run due to the size of the PR.
|
Needs rebase for conflicts. Prefer {attribution.commit: ""} for usage of Claude on Google repositories for CLA. |
083f620 to
68777e9
Compare
Thanks @jpoehnelt , does that look okay now? |
68777e9 to
8e21db6
Compare
Three related bugs caused all API calls to fail with "Access denied.
No credentials provided" even after successful `gws auth login`:
1. resolve_account() rejected valid credentials.enc as "legacy" when
accounts.json was absent, instead of falling through to use them.
2. main.rs silently swallowed all auth errors (Err(_) => None),
masking real failures behind a generic "no credentials" message.
3. auth login didn't include openid/email scopes, so
fetch_userinfo_email() couldn't identify the user, causing
credentials to be saved without an accounts.json entry.
{attribution.commit: ""}
8e21db6 to
6a5efcb
Compare
- Update stale docstring on resolve_account to reflect fallthrough behavior - Add breadcrumb comment on string-based error matching in main.rs - Move identity scope injection before authenticator build for readability
- Update stale docstring on resolve_account to reflect fallthrough behavior - Add breadcrumb comment on string-based error matching in main.rs - Move identity scope injection before authenticator build for readability Co-authored-by: jpoehnelt-bot <jpoehnelt-bot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #175 +/- ##
==========================================
+ Coverage 56.21% 56.80% +0.58%
==========================================
Files 38 38
Lines 13853 13950 +97
==========================================
+ Hits 7788 7924 +136
+ Misses 6065 6026 -39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Three related bugs caused all API calls to fail with "Access denied. No credentials provided" even after a successful
gws auth login. This happened when the userinfo endpoint couldn't identify the user's email (e.g. due to missingopenid/emailscopes), causing credentials to be saved tocredentials.encwithout anaccounts.jsonregistry entry — which then got immediately rejected as "legacy" credentials.Root Causes
resolve_account()rejected validcredentials.encas "legacy" whenaccounts.jsonwas absent, bailing with an error instead of falling through to use them.main.rssilently swallowed all auth errors (Err(_) => (None, AuthMethod::None)), masking real failures behind the generic "no credentials" message.auth logindidn't includeopenid/emailscopes, sofetch_userinfo_email()couldn't identify the user, causing credentials to be saved without anaccounts.jsonentry.Fixes
src/auth.rs:resolve_account()now returnsOk(None)when no registry exists, allowingload_credentials_innerto pick upcredentials.enc.src/main.rs: Auth errors are now propagated unless the error is specifically "No credentials found". Real failures (decryption errors, invalid tokens, etc.) are shown to the user.src/auth_commands.rs:handle_loginalways injectsopenidanduserinfo.emailscopes so the user's email can be fetched and registered inaccounts.json.Dry Run Output:
{ "body": null, "dry_run": true, "is_multipart_upload": false, "method": "GET", "query_params": { "maxResults": "1" }, "url": "https://gmail.googleapis.com/gmail/v1/users/me/messages" }Before (broken)
After (fixed)
Checklist:
AGENTS.mdguidelines (no generatedgoogle-*crates).cargo fmt --allto format the code perfectly.cargo clippy -- -D warningsand resolved all warnings.pnpx changeset) to document my changes.