Skip to content

Call loginWithToken on the OneTimeLoginLink behavior directly - #111

Open
arusinowski wants to merge 1 commit into
13.next-cake5from
fix/one-time-token-behavior
Open

arusinowski wants to merge 1 commit into
13.next-cake5from
fix/one-time-token-behavior

Conversation

@arusinowski

Copy link
Copy Markdown
Member

OneTimeTokenAuthenticator called $usersTable->loginWithToken($token). On the CakeDC/Users table that method comes from the OneTimeLoginLink behavior, so the call went through Table::__call(). Calling behavior methods through the table is deprecated since CakePHP 5.3: every magic-link login raised

Since 5.3.0: Calling behavior methods on the table instance is deprecated.
Use `$table->getBehavior('YourBehavior')->loginWithToken()` instead.

Changes

  • A users table that defines loginWithToken() itself is still called directly.
  • Otherwise the behavior is called directly, without the deprecated proxy. Its alias is the new behavior option, default OneTimeLoginLink.
  • When no behavior is loaded under that alias, the first loaded behavior that defines loginWithToken() is used, so apps that load it under another alias keep working.
  • A users table with neither the method nor such a behavior throws UnexpectedValueException naming the table and the behavior option, instead of Unknown object.
  • The psalm baseline entry for the magic call is removed.
  • Docs (Docs/Documentation/Authentication.md) and CHANGELOG.md updated.

Configuration

No change needed for CakeDC/Users. To use another behavior alias:

$service->loadAuthenticator('CakeDC/Auth.OneTimeToken', [
    'behavior' => 'MagicLink',
]);

- Call loginWithToken on the OneTimeLoginLink behavior directly
- Find the loginWithToken behavior under any alias
- Explain a missing loginWithToken behavior
@arusinowski
arusinowski requested a review from arodu December 1, 2026 18:28
@arodu

arodu commented Dec 2, 2026

Copy link
Copy Markdown
Member

🧪 Missing Tests

Low [Authenticator]: no test covers a users table that defines loginWithToken() while a behavior also provides it. The method_exists() guard at src/Authenticator/OneTimeTokenAuthenticator.php:80 and the docs promise the table method wins; swapping the two lookups would still pass every current test (testAuthenticate uses a table with no behavior, testAuthenticateWithBehavior a behavior with no table method), and an app that overrides token validation on its table would silently get the behavior's logic instead. Add a case to OneTimeTokenAuthenticatorTest with a table method plus OneTimeLoginLink loaded, asserting the table's user/token is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants