Skip to content

Commit fcb77e4

Browse files
wesmclaude
andcommitted
Save token under original identifier, not canonical email
The previous commit saved tokens under the canonical email returned by the Gmail profile API. This broke token lookup: the rest of the app (HasToken, TokenSource, source records) keys on the user-supplied identifier. If the canonical address differed (case, dots, googlemail), the token file would be unreachable. Fix: always save under the original identifier after validation confirms the account matches. sameGoogleAccount() still rejects wrong-account selection — it just no longer renames the file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6dbbc77 commit fcb77e4

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

internal/oauth/oauth.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,13 @@ func (m *Manager) authorize(
160160
// Validate the token belongs to the expected account before
161161
// persisting it. This prevents token pollution where selecting
162162
// the wrong Google account would overwrite a valid token file.
163-
canonicalEmail, err := m.resolveTokenEmail(ctx, email, token)
164-
if err != nil {
165-
return err
166-
}
167-
168-
if err := m.saveToken(canonicalEmail, token, m.config.Scopes); err != nil {
163+
// The token is always saved under the original identifier (email)
164+
// since that's the key used for all lookups elsewhere in the app.
165+
if _, err := m.resolveTokenEmail(ctx, email, token); err != nil {
169166
return err
170167
}
171168

172-
if canonicalEmail != email {
173-
fmt.Printf("Note: Google canonical address is %s "+
174-
"(saving token under this address)\n", canonicalEmail)
175-
}
176-
177-
return nil
169+
return m.saveToken(email, token, m.config.Scopes)
178170
}
179171

180172
const (

0 commit comments

Comments
 (0)