Repository navigation
Add opt-in delegated Entra token exchange - #10
Merged
Merged
Conversation
Token exchange authenticates backends against the OAuth server's client registry. Administering that registry required GOTRUE_OAUTH_SERVER_ENABLED, which also opens the authorization-code endpoints. Those issue ordinary login tokens, which a resource API that checks only the login signature and session accepts as a full session. - Serve /admin/oauth/clients whenever the registry exists: with the OAuth server or with token exchange. The public /oauth endpoints still require the OAuth server. - Accept an enabled exchange policy with no clients. It refuses every exchange, so the first backend can be registered before the policy names its client ID. An empty GOTRUE_TOKEN_EXCHANGE_CLIENTS means no clients. - Document the order of setup and why the OAuth server stays off. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
GOTRUE_TOKEN_EXCHANGE_ENABLED is removed. Exchange is on when the tenant, provider, client or signing-key setting has a value, and off when all four are empty, which is what a deployment file forwards to an installation that never configured it. The two limits do not count, because deployment files forward their defaults to every installation. A partly configured exchange stops startup and names the missing setting, so it cannot run silently off. An empty signing-key value now reads as no keys and is reported by validation. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…code This code had never been linted: the fork's checks only started running with the workflows now on appflowy4. - gosec G101 read the two RFC 8693 identifier constants as hardcoded credentials because their names contain "token". They are marked as not secrets. - staticcheck ST1005: an error string began with a capital letter. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The flag says whether a password is one the user chose. POST /user/change-password asks for the current password only when it is set, and GET /user/auth-info reports it so that Web can ask for one. Since the port to appflowy2 (2025-11) nothing stored it. The appflowy branch wrote the column in UpdatePassword's column list; the port kept the assignments in memory and dropped the column. The endpoint therefore never asked for a current password that was set after the port, and auth-info kept reporting such passwords as not chosen. - User.SetIsNonDefaultPassword stores the flag. Each place that decides it calls this in the transaction of the change it belongs to, so the flag no longer depends on an upstream column list. - POST /user/change-password and PUT /user with a password set it. Web and Desktop use PUT /user after a recovery, and Desktop for a first password. - A verified password recovery resets it. The appflowy branch reset it when a recovery was requested, which let anyone reset it for any address; the port left that as an assignment that was never saved. A magic-link sign-in and an email change do not reset it. Tests. The five that failed on appflowy4: - TestUserChangePasswordNoCurrentPasswordForDefaultPassword failed on the missing write and passes unchanged. - TestUserUpdatePasswordReauthentication and TestUserUpdatePasswordLogoutOtherSessions passed alone and failed in the suite: TestUserChangePasswordWeakPassword left the shared minimum length at 10, which refused their seven-character password. It restores it now. - TestPasswordRecoveryResetsIsNonDefaultPassword also required the recovery to delete the password, which no version of the fork did. It now requires the reset on verification only, and that the password still signs the user in. - TestEmailChangeResetsIsNonDefaultPassword required an email change to reset the flag and delete the password, and expected the change to complete after one of its two confirmations. It is replaced by a test that a completed change keeps both. New tests read the flag back through each endpoint that sets it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…no test The testing guide ran suite methods by their own name, for example `-run TestUserChangePassword`. Those tests are methods of the TestUser and TestVerify suites, so the pattern matched nothing and `go test` printed `ok ... [no tests to run]`. The migration notes recorded that as passing, for tests that could not pass. The commands now name the suite first. The notes also said the flag is reset on an email change, which the code never did and should not do, and did not say where the flag is stored. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…egated-token-exchange
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.
Delegated dashboard access
A self-hosted dashboard can exchange a signed-in user's Entra v2 access token for a five-minute, resource-scoped bearer token. The grant is off until an installation configures it. It authenticates a registered confidential client and resolves the user's existing OIDC identity by tenant and object ID. Signing keys and sessions are specific to delegated access. Access to each Cloud endpoint requires a corresponding resource-server implementation.
Turning it on
There is no enable flag. Exchange is on when
GOTRUE_TOKEN_EXCHANGE_TENANT_ID,_PROVIDER,_CLIENTSor_SIGNING_KEYShas a value, and off when all four are empty, which is what a deployment file forwards to an installation that never configured it. The two limits do not count, because deployment files forward their defaults everywhere. A partly configured exchange stops startup and names the missing setting, so it cannot run silently off. A flag defaulting totruewas not an option: an installation with nothing configured would fail validation.Registering a backend
Exchange authenticates backends against the OAuth server's client registry. GoTrue now serves
/admin/oauth/clientswhenever exchange is enabled, so the OAuth server itself stays off. Its authorization endpoints issue ordinary login tokens, which a resource API that checks only the login signature and session accepts as a full session./oauth/authorize,/oauth/tokenand/oauth/clients/registerstill answer 404 unlessGOTRUE_OAUTH_SERVER_ENABLEDis set.An exchange with no clients is valid and refuses every exchange with
invalid_client. The policy names a client ID that only registration creates, so setup needs that state. An emptyGOTRUE_TOKEN_EXCHANGE_CLIENTSmeans no clients, because deployment files forward an unset value as an empty string.Setup order: set the tenant, provider and signing keys; register the backend; name its client ID in the policy. Emptying the client list pauses issuing without removing the configuration. Operator guide
Verification
Exercised the HTTP router with PostgreSQL and signed Entra fixtures, including scope and audience isolation between dashboards, session revocation, and ordinary login and refresh during a signing-key outage.
TestTokenExchangeAdministersClientsWithoutTheOAuthServerregisters a backend through the admin API with the OAuth server off, exchanges with the secret it returned, and checks that the authorization endpoints stay closed.Run on
512e13bwith Go 1.25.14 and PostgreSQL 15:go test ./internal/api -run 'TestTokenExchange|TestOAuthServer|TestDisabledFeatureReturnsJSON' -racego test ./internal/confgo test ./internal/api/oauthserver/...andgo test ./internal/api -run 'Admin|OAuth'2d94850; the commit after it changes onlyinternal/confgo build ./...,go vet ./internal/api ./internal/conf,gofmt -lon the changed filesIn CI, on
03a4a52. The fork's checks never ran before 2026-11-25: its workflows asked for runners AppFlowy-IO does not have. They run now (#11).Check pull requestsTest: gofmt, migrations,go vet, staticcheck, gosec, govulnchecka2de885Test: test suiteTestwas red until03a4a52because five password tests failed onappflowy4itself. #12 fixes them, and its branch is merged into this one so that this pull request can be judged on its own code. Until #12 merges, its two commits (34ba15f,28edc01) show in this diff; they touch only the password feature and the notes underappflowy/. The two pull requests can merge in either order.A GoTrue image built from
03a4a52also answered 21 password-flow checks over HTTP (listed in #12). The token-exchange checks against real services (108, in the Cloud pull request) ran on512e13b; the commits since change one error string and two comments in that code.A live Entra pilot is pending.
Related PRs