Browser handoff (app → browser)
The browser handoff system lets a user authenticate in a non-browser client (e.g., the mobile app) and then bootstrap a WordPress cookie session in a real browser using a short-lived, single-use token.
Implementation
Token creation
- Function:
extrachill_users_create_browser_handoff_token( int $user_id, string $redirect_url ): string - File:
inc/auth-tokens/browser-handoff-token.php - Storage:
set_site_transient( 'ec_browser_handoff_' . $token, $payload, 60 ) - Payload:
user_id(int)redirect_url(string)created_at_ts(int)
Token consumption
- Function:
extrachill_users_consume_browser_handoff_token( string $token ) - File:
inc/auth-tokens/browser-handoff-token.php - Behavior:
- Reads payload from the site transient
- Deletes the transient immediately (single-use)
- Returns
WP_Error( 'invalid_handoff_token', ... )on invalid/expired tokens
Browser handler
- Handler:
extrachill_users_handle_browser_handoff() - File:
inc/auth/browser-handoff-handler.php - Hooks:
admin_post_nopriv_extrachill_browser_handoffadmin_post_extrachill_browser_handoff
- Input:
ec_browser_handoffquery parameter (the token)
The handler:
- Consumes the token payload.
- Validates the redirect host:
- Allows
extrachill.comand*.extrachill.com - Rejects hosts containing
extrachill.link
- Allows
- Sets the WordPress auth cookies (
wp_set_auth_cookie( $user_id, false )). - Adds the redirect host to
allowed_redirect_hostsfor the current request. - Redirects to the requested URL via
wp_safe_redirect().
Notes
- Tokens expire after 60 seconds.
- The cookie is non-persistent (
remember = false) for the handoff cookie set.