(feat) Add bearer-token auth mode and optional session URL rewriting (for use with other JMAP providers like Fastmail) - #750
Open
mdbraber wants to merge 1 commit into
Conversation
Two build-time flags, both inert unless set, so upstream behaviour is unchanged by default. NEXT_PUBLIC_JMAP_AUTH_MODE=bearer sends the login form's password field as `Authorization: Bearer <token>` instead of Basic. Needed for hosted JMAP providers that only accept bearer tokens — Fastmail answers Basic with 401 and `WWW-Authenticate: Bearer` regardless of credentials, so its API tokens cannot be used at all otherwise. JMAPClient.withBearer already existed; it was just unreachable without an OAuth or TOTP exchange. No onTokenRefresh is passed, which is correct for a static token: a 401 surfaces as an auth error rather than a refresh attempt. NEXT_PUBLIC_JMAP_REWRITE_SESSION_URLS=false disables rewriteSessionUrl. That rewrite forces every URL in the JMAP session resource onto JMAP_SERVER_URL's origin, which is right for Stalwart behind a reverse proxy advertising an internal hostname, but wrong for providers that serve blobs from a separate origin by design — Fastmail returns downloadUrl on www.fastmailusercontent.com, and rewriting it to api.fastmail.com breaks every attachment. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
My goals was to be able to connect to Fastmail as the JMAP backend. Unfortunately Fastmail does not (yet) support OAuth applications for individual users. But it does support long-lived API access tokens in the Bearer. As that infrastructure already exists in Bulwark the idea is to use the API token as password to login.
Changes
Two build-time flags, both inert unless set, so upstream behaviour is unchanged by default.
NEXT_PUBLIC_JMAP_AUTH_MODE=bearer sends the login form's password field as
Authorization: Bearer <token>instead of Basic. Needed for hosted JMAP providers that only accept bearer tokens — Fastmail answers Basic with 401 andWWW-Authenticate: Bearerregardless of credentials, so its API tokens cannot be used at all otherwise. JMAPClient.withBearer already existed; it was just unreachable without an OAuth or TOTP exchange. No onTokenRefresh is passed, which is correct for a static token: a 401 surfaces as an auth error rather than a refresh attempt.NEXT_PUBLIC_JMAP_REWRITE_SESSION_URLS=false disables rewriteSessionUrl. That rewrite forces every URL in the JMAP session resource onto JMAP_SERVER_URL's origin, which is right for Stalwart behind a reverse proxy advertising an internal hostname, but wrong for providers that serve blobs from a separate origin by design — Fastmail returns downloadUrl on www.fastmailusercontent.com, and rewriting it to api.fastmail.com breaks every attachment.
Related issues
See this discussion: https://github.com/orgs/bulwarkmail/discussions/596
Type of change
Checklist
npm run typecheck && npm run lintand there are no errorsnpm run build)locales/) if my changes affect user-facing textNotes for reviewers
This is mostly meant as a POC right now because using API keys as Bearer tokens would not be a preferred long-term solution. What it does allow is for (advanced) users to participate in using / developing Bulwark while (re)using the Fastmail infrastructure. As this is config only it could be considered a safe-enough option for users who understand what they're doing.