Add support for OAuth 2.0 (next-gen auth) login - #16
Open
Deniel9204 wants to merge 1 commit into
Open
Deniel9204 wants to merge 1 commit into
Deniel9204 wants to merge 1 commit into
Conversation
Homeservers using next-gen authentication (MSC3861), such as Continuwuity in OAuth-exclusive mode, disable interactive login entirely: /v3/login returns M_UNRECOGNIZED and only /v1/auth_metadata is available. The login screen had no way to authenticate against those servers. When getLoginFlows fails, the login screen now falls back to fetching /v1/auth_metadata and, if the auth server supports the device authorization grant, offers an OAuth login. The device-code grant is used so no custom redirect handling is needed: the app dynamically registers a public client, requests a device code, opens the verification URL in the browser, and polls the token endpoint until the user approves. The resulting access token is used as the Matrix access token.
Deniel9204
force-pushed
the
feat/oauth-login
branch
from
August 29, 2026 18:22
33ef4f9 to
9e5bf6d
Compare
Author
|
Validated the network side against a live Continuwuity (OAuth-exclusive) instance: dynamic registration → 201, device authorization with the stable |
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.
Problem
Homeservers using next-generation authentication (MSC3861) disable interactive login. On such a server — e.g. Continuwuity with
oauth.compatibility_mode = exclusive— the client-server API responds:The login screen is driven entirely by
/v3/login, so it renders neither the password form nor the SSO button, and there is no way to log in. Everything the client needs is instead advertised at/_matrix/client/v1/auth_metadata.Change
When
getLoginFlows()fails, the login screen falls back toGET /v1/auth_metadata. If the auth server advertises the device authorization grant, it offers an OAuth login button.The device-code grant (RFC 8628) is used deliberately: it needs no redirect URI, so it reuses the existing
openInBrowser+doClientHTTPplumbing and requires no changes to the custom-protocol handling. The flow:registration_endpoint(RFC 7591); theclient_idis cached inlocalStorageper issuer.device_authorization_endpoint) with scopeurn:matrix:client:api:* urn:matrix:client:device:<id>.token_endpoint(handlingauthorization_pending/slow_down) until approval./whoamiresolves the user and device ID.All OAuth requests to the auth server go through the main-process
doClientHTTP(the endpoints live on the auth server's origin, not the homeserver's). The legacy password/SSO paths are untouched — the OAuth UI only appears when interactive login is unavailable.Files:
src/api/oauth.ts(new),src/api/matrixclient.ts(getAuthMetadata),src/app/MatrixLogin.tsx,src/types/matrix.ts,src/app/MatrixLogin.css.Testing
npm run lint(tsc --noEmit && eslint) passes clean.201, the client metadata above accepted verbatim.200, the stableurn:matrix:client:api:*scope accepted; device/user codes returned.400 {"error":"authorization_pending"}— the exact shape the poll loop handles.One environment note from that server: its device-authorization response omits
interval(defaults to 5s per RFC 8628) and returns a shortexpires_in(60s); both are handled.