Repository navigation
fix(sso): test the connection with the configured redirect URI - #440
Open
SebastianOehm wants to merge 2 commits into
Open
SebastianOehm wants to merge 2 commits into
SebastianOehm wants to merge 2 commits into
Conversation
Background The single sign-on "Test connection" (POST /api/settings/oidc/test) checks the client by redeeming a made-up authorization code. It sent redirect_uri = <issuer origin>/auth/oidc/callback, a URI that is never the registered one because the provider runs on another host. Authentik compares the redirect URI with its strict list before it looks at the code and answers a mismatch with invalid_client, so the test always failed and blamed the client ID, secret and auth method, while the real login (which uses resolveRedirectUri()) worked. Changes - services/oidcService.js: testConnection() takes redirectUri and sends it in the probe instead of the issuer origin. The invalid_client message adds that some providers answer the same way for an unregistered redirect URI and names the URI that was sent. - routes/settingsConnections.js: the test endpoint accepts an optional redirectUri (400 when it is not an absolute http(s) URL); empty falls back to resolveRedirectUri(req), i.e. OIDC_REDIRECT_URI, else the callback derived from the request (honours TRUST_PROXY). Swagger updated. - public/js/modules/settings-sso.js: the test sends the Redirect URI field like every other field it tests, or the detected URI when it is empty. - OPENAPI/openapi.json: regenerated. - tests/test-settings-oidc.js: the fake provider records redirect_uri and can enforce a strict redirect list (invalid_client on mismatch, like Authentik). New cases: typed URI sent to a strict provider, stored OIDC_REDIRECT_URI used when none is typed, derived URI used when none is stored (never the issuer origin), unregistered URI named in the error, malformed URI refused with 400. Five of them fail without the fix. Testing - node scripts/run-tests.js --all: 155 passed, 8 skipped (need a server or poppler), 0 failed; same as before the change. - test-settings-oidc: 28 passed; with the old service and route 5 fail. - npx eslint and prettier --check on the changed files, npm run typecheck, regen-openapi.js committed. - End to end with the Docker image and a strict fake provider (issuer .../application/o/zettelrobbe/): empty Redirect URI field (detected URI), the registered URI typed, SSO switched off and on all report success; an unregistered URI fails and the message names it. The image built from main sends http://<issuer host>/auth/oidc/callback and fails. Impact Settings page connection test only. The login flow is unchanged. API callers that omit redirectUri now get the URI a login would use. Upstream Status Not applicable; single sign-on is specific to this fork. Fixes admonstrator#438
Resolve the conflict in the invalid_client message of
oidcService.testConnection(): keep main's new wording ("token
authentication") and append this branch's redirect URI hint.
This branch has not been deployed
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.
Fixes #438
Problem
"Test connection" on Settings → Single sign-on checks the client by redeeming a made-up authorization code at the token endpoint. The request sent
redirect_uri = <issuer origin>/auth/oidc/callback. The issuer almost always runs on a different host than Zettelrobbe, so that URI is usually not the registered one. Authentik compares the redirect URI with its strict list and answers a mismatch withinvalid_client, so in the reporter's setup the test always failed and told the user to check the client ID, secret and auth method, even though the actual login (which usesresolveRedirectUri()) worked.Changes
services/oidcService.js:testConnection()takes aredirectUriand sends it in the probe instead of the issuer origin. Theinvalid_clientmessage keeps its hint about client ID, secret and auth method, and now adds that some providers answer the same way when the redirect URI is not registered, naming the URI that was sent.routes/settingsConnections.js:POST /api/settings/oidc/testaccepts an optionalredirectUri(400 "The redirect URI must start with https:// or http://." if it is not an absolute http(s) URL). When it is empty or missing, the endpoint usesresolveRedirectUri(req), the same value a login uses:OIDC_REDIRECT_URI, otherwise the callback derived from the request. Swagger JSDoc updated. This route is the only caller oftestConnection().public/js/modules/settings-sso.js: the test button sends the Redirect URI field like the other fields it tests (unsaved values), or the detected URI when the field is empty. The page therefore always sends a value; the server-side fallback matters for direct API calls.OPENAPI/openapi.json: regenerated.tests/test-settings-oidc.js: the fake provider recordsredirect_uriand can enforce a strict redirect list (invalid_clienton mismatch, like Authentik). Four new test cases (typed URI, with surrounding spaces, sent to a strict provider; storedOIDC_REDIRECT_URIused when none is typed; request-derived URI used when none is stored, never the issuer origin; unregistered URI named in the error) plus a malformedredirectUriadded to the existing 400 input test. All five checks fail without the fix.The login flow itself is unchanged; only the Test connection button and its endpoint behave differently, and the test still saves nothing.
Testing
node scripts/run-tests.js --all: 155 test files passed, 8 skipped (need a running server or poppler), 0 failed; the same result as onmain(no test files added).test-settings-oidc: 28 checks passed; with the old service and route, 5 fail.npm run typecheck,regen-openapi.jsresult committed..../application/o/zettelrobbe/). An empty Redirect URI field (detected URI) and the registered URI typed in both report success, with SSO switched off and on. An unregistered URI fails and the message names it. An image built frommainsendshttp://<issuer host>/auth/oidc/callbackand fails, which reproduces the report. Not tested against a real Authentik instance.