mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 08:30:39 +00:00
Support authme action from URL query
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test-backend (24.x) (push) Has been cancelled
test / API tests (node env, api-test) (24.x) (push) Has been cancelled
test / puterjs (node env, vitest) (24.x) (push) Has been cancelled
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test-backend (24.x) (push) Has been cancelled
test / API tests (node env, api-test) (24.x) (push) Has been cancelled
test / puterjs (node env, vitest) (24.x) (push) Has been cancelled
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.
This commit is contained in:
+52
-5
@@ -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 <strong>${html_encode(redirectURL)}</strong>?`,
|
||||
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 <strong>${html_encode(redirectURL)}</strong>?`,
|
||||
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 });
|
||||
|
||||
Reference in New Issue
Block a user