diff --git a/v3.0/packages/auth/adapters.md b/v3.0/packages/auth/adapters.md index 261f33c..e2bfeb1 100644 --- a/v3.0/packages/auth/adapters.md +++ b/v3.0/packages/auth/adapters.md @@ -13,37 +13,38 @@ $auth->signin($email, $password, true); ### What it does -After a successful sign-in without two-factor interruption, the adapter: +When a user signs in, the adapter: - regenerates the PHP session ID - stores the authenticated user under the `auth_user` session key - stores only schema fields marked as `visible` +It does this in each of the three places a sign-in completes: in `signin()` without two-factor authentication, in `verifyOtp()` once the OTP is accepted, and in `user()` when the remember cookie signs the user in. The new session ID means that an ID known before the sign-in, for example one planted in the browser, does not lead to the signed-in session. The other data in the session is kept. + `user()` first reads from session storage. If no session user exists, it can restore the user from the remember-token cookie. ### Remember-me behavior -Passing `true` as the third argument to `signin()` enables remember-me behavior. +Passing `true` as the third argument to `signin()` enables remember-me behavior. The adapter generates a remember token, stores it through your auth service and writes it to a cookie: -The adapter then: +- without two-factor authentication, during `signin()` +- with two-factor authentication, only when `verifyOtp()` accepts the OTP, in the browser that signed in -- generates a remember token -- stores that token through your auth service -- writes the token to a cookie +Until the OTP is verified, `signin()` only keeps the request in that browser's session. A later `signin()` without "remember me", and `signout()`, drop it. A sign-in whose OTP is never entered therefore leaves no cookie that could sign in later. The remember cookie lifetime comes from `auth.session.remember_lifetime`. If that setting is absent, the default is `2592000` seconds (30 days). +On sign-out, the adapter deletes the session user, regenerates the session ID, clears the stored remember token, and deletes the cookie. + ### When the settings are read The adapter reads `two_fa`, `otp_expires` and `session.remember_lifetime` once, when it is built. An invalid value, such as an `otp_expires` that is not a [whole number](../config/contracts.md#typed-reader-contract), therefore fails there, also while two-factor authentication is off, and never halfway through a sign-in. An auth adapter of your own that uses `Quantum\Auth\Traits\AuthTrait` implements `readConfig(ConfigSection $config)` to read its settings the same way. -On sign-out, the adapter deletes the session user, regenerates the session ID, clears the stored remember token, and deletes the cookie. - ### Two-factor caveat -When two-factor auth is enabled, `signin()` returns an OTP token instead of logging the user in immediately. +When two-factor auth is enabled, `signin()` returns an OTP token instead of logging the user in immediately, and `verifyOtp()` completes the sign-in. See [Two-factor flow](usage.md#two-factor-flow). -If a remembered user still has a pending OTP token in storage, the adapter refuses to restore that user from the remember cookie. +If a remembered user has a pending OTP token in storage, for example from a sign-in that was started but not completed, the adapter refuses to restore that user from the remember cookie until an OTP is verified. ## JWT adapter diff --git a/v3.0/packages/auth/usage.md b/v3.0/packages/auth/usage.md index 448db36..481b5c8 100644 --- a/v3.0/packages/auth/usage.md +++ b/v3.0/packages/auth/usage.md @@ -55,9 +55,11 @@ $result = auth()->verifyOtp($otp, $otpToken); Result shape depends on the adapter: -- session adapter: `true` and the user is written to session +- session adapter: `true`; the user is written to the session under a new session ID, and when `signin()` was called with "remember me", this is the step that sets the remember cookie - JWT adapter: fresh `accessToken` and `refreshToken` values +Call `verifyOtp()` in the same browser that called `signin()`, as the starter project's verify page does: the "remember me" request is kept in that browser's session. See [Remember-me behavior](adapters.md#remember-me-behavior). + If the code expires, verification fails with an auth exception. OTP expiry defaults to 2 minutes unless `otp_expires` is configured (see [When the settings are read](adapters.md#when-the-settings-are-read)). ## Registration and activation