Repository navigation
Accept Basic client auth, deliver sent Gmail, and support service accounts in the Google emulator - #406
Accept Basic client auth, deliver sent Gmail, and support service accounts in the Google emulator#406ctate wants to merge 5 commits into
Conversation
…ounts in the Google emulator
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| const accessToken = issueAccessToken( | ||
| store, | ||
| tokenMap, | ||
| user ?? { email: account.client_email, id: 0 }, | ||
| scope, | ||
| revocationKey, | ||
| ); |
There was a problem hiding this comment.
with google.strict_scopes, tokens issued without sub get 401 on every api route instead of acting as the service account. let the user lookup in the auth middleware fall back to seeded service accounts, or say in the docs that strict mode needs sub.
repro: seed strict_scopes: true, POST /oauth2/token with a signed assertion without sub (scope drive) then GET /drive/v3/files with the token -> token is 200, the api call is 401 UNAUTHENTICATED (same token flow returns 200 without strict mode)
| const user = gs.users.all().find((candidate) => candidate.email.toLowerCase() === address); | ||
| if (!user) continue; | ||
| if (address === sender) { | ||
| result = markMessageModified(gs, result, [...result.label_ids, "INBOX", "UNREAD"]); |
There was a problem hiding this comment.
a message sent to yourself gets INBOX and UNREAD back even when your own filter removed them, unlike the recipient copies. skip the labels the sender's matching filters remove.
| const TOKEN_AUDIENCES = new Set([ | ||
| "https://oauth2.googleapis.com/token", | ||
| "https://accounts.google.com/o/oauth2/token", | ||
| "https://www.googleapis.com/oauth2/v4/token", | ||
| ]); |
There was a problem hiding this comment.
the emulator's own token url is refused as aud, and go's x/oauth2 signs exactly that when token_uri points here. accept ${baseUrl}/oauth2/token as an audience too.
The mailbox-list parser stopped an atom at every character that can end one, but a closing parenthesis outside a comment or a quoted string had no branch of its own. The atom branch then began and ended at the same position, so the tokenizer added empty atoms and never advanced. A From supplied to messages.send or drafts.send could therefore block the event loop. A closing parenthesis that is not part of a comment now makes the header invalid, and the atom branch refuses an empty token, so every iteration either moves forward or rejects the header. Delivery then replaces the malformed From with the sender's default send-as address, as it does for any From that is not one checked mailbox. The test "rewrites a malformed From without stalling" covers structured, raw MIME, and draft sends, checks the recipient's From field and raw header, and bounds the elapsed time.
client_secret_basiccredentials, refusing body credentials that differ from the header with Google'sinvalid_request, and accepts the service account JWT bearer grant, issuing tokens that act as asubuser only whengoogle.domain_wide_delegationgrants every requested scope.messages.sendanddrafts.senddeliver an unread inbox copy without theBccheader to each recipient who is an emulator user, and a message sent to oneself is labeledSENT,INBOX, andUNREAD.