web/flows: complete Plex source sign-in with a forwardUrl redirect instead of a popup
Details
Closes #24613
The Plex flow stage opened its popup from inside a setTimeout, which has no transient user activation, so current browsers block it and every sign-in fell through to the manual button. When the identification stage auto-redirects to a sole Plex source there is no gesture at all, so a popup can never open in that shape of flow. And because getPin never set Plex's forwardUrl, users who signed in from the fallback tab were left sitting on plex.tv while the backgrounded opener did the polling.
This replaces the popup on the flow stage with a same-tab redirect:
- The stage sends the tab to app.plex.tv with
forwardUrlset to the current flow URL, query string included, sonext=still routes the finished flow back to the application. The pin id and an attempt counter live in namespaced sessionStorage keys rather than the query string: a pin id in the URL would let a crafted link hand a victim an attacker-authorized pin and sign them in as the attacker's Plex account. A blocked storage write reports that and does not redirect, since a trip whose return leg cannot be recognized has no way to complete. - On return the stage does a single
pinStatuscheck instead of polling, since Plex only followsforwardUrlonce the pin is authorized. An unauthorized pin mints a fresh one, capped at two automatic attempts so a broken return path cannot loop. The counter clears as soon as a return leg arrives, because reaching that point proves the return path works. - A cancelled sign-in, a failed redeem, a failed mint, blocked storage, and the attempt cap each render an actionable retry state instead of leaving a permanent spinner above a button that does nothing.
The two callers that keep the popup, the admin source form and user source settings, both awaited the pin request before opening the window, so the click's activation was already spent and the popup was blocked regardless of where window.open sat. They now open about:blank inside the click and navigate the returned window once the pin arrives. popupCenterScreen loses its async signature with that, since an awaitable signature is what invited the problem, and both callers now handle a pinPoll rejection, which is where an expired pin and an unopened popup both end up.
The auth URL uses the #? form that app.plex.tv documents, which is the form forwardUrl is known to work with.
Tested with this logic running against 2026.5.6 on my own deployment: desktop Chrome and Firefox, and iOS Safari including a Private window over cellular, on a flow whose identification stage auto-advances to Plex with no interaction. The return trip resumes the flow and completes the /application/o/authorize/ redirect back to the application. sessionStorage does survive the cross-origin round trip in an iOS Safari Private window, which I had assumed would be the weak point of carrying state there. The popup change is reasoned rather than exercised, since my deployment does not use the admin or user-settings paths.
Known limitation, not addressed here: on a flow with multiple sources or user fields, source selection is client-side and the server-side flow plan stays on identification, so a returning user lands back on identification and has to click Plex again. That completes immediately, since the stored pin is already authorized. Tracking the left-off stage server-side is out of scope.
Deploy Preview for authentik-storybook ready!
| Name | Link |
|---|---|
| Latest commit | 84d14ebc1570a107e18eac4577a9ebc00ac35b7b |
| Latest deploy log | https://app.netlify.com/projects/authentik-storybook/deploys/6ace242beb0db731a8467df9 |
| Deploy Preview | https://deploy-preview-24614--authentik-storybook.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
Deploy Preview for authentik-docs ready!
| Name | Link |
|---|---|
| Latest commit | fc1088c1098122da5b7a8b74fd6c7b8aafaafbfb |
| Latest deploy log | https://app.netlify.com/projects/authentik-docs/deploys/6a7452d8d8f1ab00087a8aa6 |
| Deploy Preview | https://deploy-preview-24614--authentik-docs.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 92.32%. Comparing base (2547ba4) to head (d3d8388).
Additional details and impacted files
@@ Coverage Diff @@
## main #24614 +/- ##
==========================================
- Coverage 92.33% 92.32% -0.02%
==========================================
Files 1175 1175
Lines 77789 77813 +24
Branches 4129 4129
==========================================
+ Hits 71827 71838 +11
- Misses 5896 5909 +13
Partials 66 66
| Flag | Coverage Ξ | |
|---|---|---|
| conformance | 32.91% <0.00%> (-0.01%) |
:arrow_down: |
| e2e | 37.70% <0.00%> (-0.02%) |
:arrow_down: |
| integration | 29.21% <0.00%> (-0.50%) |
:arrow_down: |
| rust | 46.45% <ΓΈ> (ΓΈ) |
|
| unit | 93.77% <100.00%> (+0.02%) |
:arrow_up: |
| unit-migrate | 93.77% <100.00%> (+0.02%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
@GirlBossRush & @kensternberg-authentik please let me know if anything is needed for this PR. π
@GirlBossRush @BeryJu I've rebased this onto current main (the conflicts were only the oxfmt reformat) and added the AI disclosure and checklist the template asks for now. Could one of you approve the workflows and take a look when you get a chance? Plex sign-in still breaks the same way on main.
I've been running this PR in production since this morning and wanted to report back, because it fixes a real problem for my users and I think it deserves a review.
My setup: self-hosted authentik in front of a Plex media portal for family and friends. Most of them are on phones and not technical. The login flow is an identification stage with no user fields and a single Plex source, so it auto-advances straight into Plex. The apps send users to authentik over OIDC. With stock authentik, people on phones either got the popup blocked or ended up on Plex's "You may now close this window" page in a new tab with no idea how to get back. My parents got stuck on exactly that a couple of days ago.
What I did: I upgraded to 2026.8.3, ported this PR onto it, and deployed it as a small overlay image. The PR doesn't apply cleanly to version/2026.8.3, so I re-applied it by hand. A whole-file diff against your head commit (8af8945) shows only import order and formatting differences. On a real Android phone in Chrome (incognito), Plex sign-in now stays in one tab, comes back to the flow, and lands in the app that started the OIDC request. That was the whole point, so thank you for this.
Before deploying I had my bug-hunter agent (Opus 5.5) go through the PR adversarially. It ran the PR's actual TypeScript in a stubbed harness and in Chromium. It found three problems.
1. A leftover pin blocks the next sign-in (the one that matters).
A return from Plex is detected only by "there is a pin in sessionStorage". Say someone gets to Plex and leaves without being forwarded back: Back button, Plex's expired page, typing another URL. The pin stays. Their next fresh sign-in in that tab shows "Sign-in with Plex was cancelled or timed out." instead of going to Plex.
Fix: the forwardUrl carries a plex_return=1 marker, and a stored pin only counts as a return when the page was loaded with that marker. An unmarked pin is dropped and a fresh redirect starts. The marker is stripped from the address bar after it's read. The pin still never goes in the URL.
2. A redeem that isn't a redirect goes to a 404.
After redeem_token the stage navigates to to unconditionally. Access denied, a source not set up for enrollment, a user-matching deny or a failed policy all return 200 with a challenge that has no to. The browser goes to /if/flow/<slug>/undefined and gets a 404. Stock does the same thing, but this PR rewrites that block, so it seemed like the place to fix it.
Fix: read the raw response and parse it with ChallengeTypesFromJSON, like the flow executor does. Follow a redirect; otherwise set the challenge on the host, the way the identification stage does, so the user sees the real reason. With no host it shows the retry state. One detail that bit us: the generated client parses every answer as a RedirectChallenge and drops the denied page's body, so using the typed response renders a blank page.
3. A failed pin request leaves a blank popup open (admin and user settings only).
PlexSourceForm and SourceSettingsPlex now open the popup before awaiting the pin, which is correct for popup blockers. But if the plex.tv pin request fails, the error escapes before any catch. The about:blank popup stays open, nothing is shown, and the rejection is unhandled.
Fix: close the popup and show the error, sharing the existing catch.
The fixes are separate patches on top of the unmodified port, so each one can be taken or left on its own:
https://github.com/JordanFromIT/authentik-plex-redirect/tree/main/patches
(0001 is your PR as ported, 0002 to 0004 are the fixes.)
Testing on 2026.8.3:
- Patched and unpatched trees give the same
tsc,lint-checkandprettier-checkresults. - Vitest goes from 82 passing to 93 passing. The 11 new tests are browser tests in Chromium covering the three fixes. Each fix's tests fail without the fix and pass with it.
- A second review of the fixed version added more cases: a realistic authorize query (
+,%2B,~,%20,next) survives the marker strip value for value, the marker never ends up insidenext, and the full path through a real FlowExecutor (auto-advance, return, denied) renders the reason without navigating. - Checked against app.plex.tv's own auth JS: an encoded
next=/application/o/authorize/?...in forwardUrl comes back byte-identical. Plex forwards about 500 ms after a successful link and also about 5 s after a failure, which the PR's error state covers. - Real device: Android Chrome. You covered desktop and iOS Safari.
Happy to open a PR against your branch with the three fixes if that's easier for you.
@JordanFromIT thanks, this is great. Good to hear it holds up on Android too.
I applied the three patches on top of 8af8945 (git am -3, no conflicts) and went through them. All three are right:
- The stale pin is a real gap. I only ever tested the round trip completing, never someone bailing out at Plex and coming back later. The marker is the right call: it says "this load is a return" without putting any state in the URL, and stripping it afterwards keeps Back from replaying it.
- For the non-redirect answer I checked the server side. redeem_token passes get_flow() through to_stage_response, which turns the access denied and "no enrollment flow" template responses into a 200 shell challenge with no
to. So the /undefined 404 is real and predates this PR. Reading the raw answer is the right fix without touching the schema. - The popup one is an oversight on my part. Reordering the open moved the pin request outside the catch.
One thing from running it on main: upstream swapped eslint and prettier for oxlint and oxfmt after 2026.8, and the new test files trip both (multiline-statement-padding warnings and formatting). pnpm run lint then pnpm run format from web/ fixes all of it, whitespace only. With that, tsc, lit-analyse, the unit project and the browser project all pass here, and 7 of your 11 tests fail with the fixes reverted, which is what I wanted to see. Worth knowing that CI only runs the "Unit Tests" project, so the browser tests won't run upstream. The repo has other .browser.test.ts files in the same boat, so I'd keep them.
Yes please, open the PR against web-plex-forward-url on my fork, based on 8af8945, with the three commits kept separate. I'll rebase-merge it so they land in this PR under your name, and I'll add a line to the description about your fixes and your Claude use on them, since the AI policy wants everything disclosed in one place.
@MrRussLuther Thank you for putting this PR together and being so patient while we review the changes. The initial testing looks promising and has revealed some flakey aspects of the Playwright suite.
This should be mergable soon -- likely before the feature freeze at the end of October.
@GirlBossRush thanks for picking this up, and for the commits on top. The identification hand-back takes care of the multi-source limitation I'd left out of scope, and good catch on the friends endpoint returning 410.
@JordanFromIT's popup fix overlaps with 8775d1d, so that one's covered. His other two aren't in the branch yet: the stale pin marker (a leftover pin from an abandoned trip turns the next sign-in into "cancelled or timed out"), and handing non-redirect redeem answers to the flow instead of navigating to /undefined. He has them in a PR against my fork, but it's based on the old head. Want me to rebase them onto your branch, or would you rather take them as a follow-up after this merges?
@GirlBossRush with the freeze close I've put @JordanFromIT's two remaining fixes on top of your head rather than wait, authored by him: d282125 ignores a stored pin unless the page is a return from Plex (a plex_return marker on the forwardUrl, checked by the stage and by the identification hand-back), and 84d14eb hands a non-redirect redeem answer to the flow executor instead of navigating to /undefined. The web checks pass locally, including the browser project. If you'd rather land this without them, say so and I'll move them to a follow-up PR.
@GirlBossRush main has moved under this since the 10-06 push and it now conflicts, but only in form.css: your "Fix static form layout" commit landed on main as 6a463bf7 and 7202f162 then touched the same lines, so a rebase just drops that commit and takes main's version. Happy to rebase and repush if that helps, or I'll leave the branch alone if you're already on it. Now that it's on the 2026.11.0 milestone I'd like to get it in before the freeze.
Don't want to add an unnecessary comment, but is there any update on when this might get merged? Still hitting this on 2026.8.5, iOS Safari users get left on plex.tv after signing in and the original tab never moves on, and the iOS 26 home screen web app just doesn't work at all since there's no tab to go back to. My setup is a proxy provider in forward auth (single application) in front of Seerr with a Plex source, so for anything used like a Plex portal it's pretty much broken on mobile right now. This fix would improve things massively, so thanks for putting it together @MrRussLuther