From 97cf80b068847f50e1b633da08ce277ca159be33 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sun, 1 Feb 2026 11:51:29 -0800 Subject: [PATCH] Support authme action from URL query Read the 'action' value from URL query params and handle a new 'authme' action. When 'authme' is present, prompt the user to approve redirecting to the provided redirectURL; if approved, append the current auth token as a 'token' query parameter and navigate to that URL. The prompt is shown in two places (after auth data is updated and before loading the desktop) to cover different entry flows. Also removed a stray blank line. --- src/gui/src/initgui.js | 57 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/src/gui/src/initgui.js b/src/gui/src/initgui.js index bfa760cc0..2b00779bb 100644 --- a/src/gui/src/initgui.js +++ b/src/gui/src/initgui.js @@ -152,7 +152,7 @@ if ( jQuery ) { } // are we in dashboard mode? -if(window.location.pathname === '/dashboard' || window.location.pathname === '/dashboard/'){ +if ( window.location.pathname === '/dashboard' || window.location.pathname === '/dashboard/' ) { window.is_dashboard_mode = true; } @@ -345,6 +345,8 @@ window.initgui = async function (options) { let action; if ( window.url_paths[0]?.toLocaleLowerCase() === 'action' && window.url_paths[1] ) { action = window.url_paths[1].toLowerCase(); + } else if ( window.url_query_params.has('action') ) { + action = window.url_query_params.get('action').toLowerCase(); } //-------------------------------------------------------------------------------------- @@ -359,7 +361,7 @@ window.initgui = async function (options) { // Puter is in fullpage mode. window.is_fullpage_mode = true; - } else if (window.is_dashboard_mode) { + } else if ( window.is_dashboard_mode ) { window.is_fullpage_mode = true; } @@ -501,7 +503,6 @@ window.initgui = async function (options) { else if ( action === 'signup' ) { await UIWindowSignup(); } - // ------------------------------------------------------------------------------------- // If in embedded in a popup, it is important to check whether the opener app has a relationship with the user // if yes, we need to get the user app token and send it to the opener @@ -613,10 +614,33 @@ window.initgui = async function (options) { } window.update_auth_data(whoami.token || window.auth_token, whoami); + // ------------------------------------------------------------------------------------- + // Action: AuthMe — redirect to a third-party URL with the user's auth token + // ------------------------------------------------------------------------------------- + if ( action === 'authme' ) { + const redirectURL = window.url_query_params.get('redirectURL'); + if ( redirectURL ) { + const approved = await UIAlert({ + message: `Do you want to authorize and redirect to ${html_encode(redirectURL)}?`, + buttons: [ + { label: i18n('approve') || 'Approve', value: 'approve', type: 'primary' }, + { label: i18n('cancel'), value: 'cancel', type: 'secondary' }, + ], + type: 'confirm', + }); + if ( approved === 'approve' ) { + const url = new URL(redirectURL); + url.searchParams.set('token', window.auth_token); + window.location.href = url.href; + return; + } + } + } + // ------------------------------------------------------------------------------------- // Load desktop, only if we're not embedded in a popup and not on the dashboard page // ------------------------------------------------------------------------------------- - if ( ! window.embedded_in_popup && ! window.is_dashboard_mode ) { + if ( !window.embedded_in_popup && !window.is_dashboard_mode ) { await window.get_auto_arrange_data(); puter.fs.stat({ path: window.desktop_path, consistency: 'eventual' }).then(desktop_fsentry => { UIDesktop({ desktop_fsentry: desktop_fsentry }); @@ -1120,10 +1144,33 @@ window.initgui = async function (options) { // close all windows $('.window').close(); + // ------------------------------------------------------------------------------------- + // Action: AuthMe — redirect to a third-party URL with the user's auth token + // ------------------------------------------------------------------------------------- + if ( action === 'authme' ) { + const redirectURL = window.url_query_params.get('redirectURL'); + if ( redirectURL ) { + const approved = await UIAlert({ + message: `Do you want to authorize and redirect to ${html_encode(redirectURL)}?`, + buttons: [ + { label: i18n('approve') || 'Approve', value: 'approve', type: 'primary' }, + { label: i18n('cancel'), value: 'cancel', type: 'secondary' }, + ], + type: 'confirm', + }); + if ( approved === 'approve' ) { + const url = new URL(redirectURL); + url.searchParams.set('token', window.auth_token); + window.location.href = url.href; + return; + } + } + } + // ------------------------------------------------------------------------------------- // Load desktop, if not embedded in a popup and not on the dashboard page // ------------------------------------------------------------------------------------- - if ( ! window.embedded_in_popup && ! window.is_dashboard_mode ) { + if ( !window.embedded_in_popup && !window.is_dashboard_mode ) { await window.get_auto_arrange_data(); puter.fs.stat({ path: window.desktop_path, consistency: 'eventual' }).then(desktop_fsentry => { UIDesktop({ desktop_fsentry: desktop_fsentry });