Skip to content

Commit de0a3ed

Browse files
authored
docs: document OAuth/forum auth changes in 2.0 upgrade guide (#511)
Covers ResponseFactory::make() signature change, removal of authenticationComplete(), makeLoggedInResponse/makeRegistrationResponse promoted to protected, the new POST /api/registration-token endpoint, _flarum_auth and _flarum_linked query params, and SignUpModal label additions. Includes a warning pointing developers to the fof/oauth upgrade notes for the companion package changes.
1 parent 962f6b4 commit de0a3ed

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

docs/extend/update-2_0.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,74 @@ Checkout this example from the mentions extension:
413413

414414
:::
415415

416+
### OAuth / Forum Auth
417+
418+
##### <span class="breaking">Breaking</span>
419+
420+
**`ResponseFactory::make()` — new `$returnTo` argument and return type change**
421+
422+
`Flarum\Forum\Auth\ResponseFactory::make()` now requires a fourth argument `string $returnTo = '/'` and always returns a `RedirectResponse` instead of an `HtmlResponse`. The old popup-based HTML response has been removed entirely.
423+
424+
```php
425+
// Before
426+
$this->response->make($provider, $identifier, $configureRegistration);
427+
428+
// After — pass a validated same-origin returnTo URL
429+
$this->response->make($provider, $identifier, $configureRegistration, $returnTo);
430+
```
431+
432+
The `$returnTo` value must be a validated same-origin relative path (starting with `/`). Passing an absolute URL is a security risk — validate it before passing it in.
433+
434+
**`ForumApplication::authenticationComplete()` removed**
435+
436+
`authenticationComplete()` existed solely to close the old popup window. It has been removed. Extensions that called it can drop the call entirely — the new redirect flow handles everything server-side.
437+
438+
**`makeLoggedInResponse()` and `makeRegistrationResponse()` are now `protected`**
439+
440+
Both helper methods on `ResponseFactory` are now `protected`, making them official extension points. Subclass `ResponseFactory` and override either method to customise login redirect behaviour or the registration handoff mechanism.
441+
442+
```php
443+
class MyResponseFactory extends ResponseFactory
444+
{
445+
protected function makeLoggedInResponse(User $user, string $returnTo): ResponseInterface
446+
{
447+
// Custom behaviour — e.g. append your own query params
448+
return parent::makeLoggedInResponse($user, $returnTo);
449+
}
450+
}
451+
```
452+
453+
Bind your subclass in a service provider:
454+
455+
```php
456+
$this->container->extend(ResponseFactory::class, fn () => new MyResponseFactory(...));
457+
```
458+
459+
**New `POST /api/registration-token` endpoint**
460+
461+
A new unauthenticated endpoint accepts a short-lived registration token in the POST body and returns only `username`, `email`, and `provided[]`. Sensitive fields (provider name, identifier, payload internals) are never exposed. The token is submitted in the body — not the URL — so it never appears in server access logs, browser history, or Referer headers.
462+
463+
This endpoint is CSRF-exempt (token possession is the credential) and is primarily used by the frontend to pre-populate the sign-up modal after an OAuth redirect.
464+
465+
**`_flarum_auth` and `_flarum_linked` query parameters**
466+
467+
The new redirect flow uses two query parameters appended to the `returnTo` URL:
468+
469+
* `_flarum_auth=<token>` — set when a new user arrives via OAuth and must complete registration. The frontend detects this on boot, strips it, fetches `username`/`email`/`provided` from `POST /api/registration-token`, and opens the `SignUpModal` pre-populated.
470+
* `_flarum_linked=<provider>` — set when an existing user's account is linked to an OAuth provider for the first time (either via email-match during login, or a manual link from the security page). The frontend detects this on boot and shows a confirmation modal.
471+
472+
Both parameters are stripped from the URL immediately on the client without a page reload.
473+
474+
:::warning fof/oauth also updated
475+
476+
If your extension extends or depends on **FriendsOfFlarum/oauth**, that package has been significantly updated alongside these core changes. The popup flow has been removed, `AbstractOAuthController` has moved from `fof/extend` into `fof/oauth` itself, and several other breaking changes apply. See the fof/oauth upgrade notes for the full migration guide.
477+
478+
:::
479+
480+
#### <span class="notable">Notable</span>
481+
482+
* `SignUpModal` fields (Username, Email, Password) now render a visible `<label>` element above each input. If your extension renders additional fields in `SignUpModal`, consider adding a label for consistency.
483+
416484
### Miscellaneous
417485

418486
##### <span class="breaking">Breaking</span>

0 commit comments

Comments
 (0)