mirror of
https://github.com/HeyPuter/puter.git
synced 2026-07-09 08:42:08 +00:00
oidc referrer
This commit is contained in:
@@ -166,10 +166,19 @@ export class OIDCController extends PuterController {
|
||||
}
|
||||
}
|
||||
|
||||
const rawReferrer = Array.isArray(req.query.referrer)
|
||||
? req.query.referrer[0]
|
||||
: req.query.referrer;
|
||||
const referrer =
|
||||
rawReferrer != null && rawReferrer !== ''
|
||||
? String(rawReferrer)
|
||||
: null;
|
||||
|
||||
const statePayload: Record<string, unknown> = {
|
||||
provider,
|
||||
redirect_uri: appRedirectUri,
|
||||
};
|
||||
if (referrer) statePayload.referrer = referrer;
|
||||
if (embeddedInPopup && msgId) {
|
||||
statePayload.embedded_in_popup = true;
|
||||
statePayload.msg_id = msgId;
|
||||
@@ -233,6 +242,7 @@ export class OIDCController extends PuterController {
|
||||
const resolved = await this.#resolveOrCreateOIDCUser(
|
||||
provider,
|
||||
userinfo,
|
||||
(stateDecoded.referrer as string) ?? null,
|
||||
);
|
||||
if ('error' in resolved) {
|
||||
console.warn(
|
||||
@@ -293,6 +303,7 @@ export class OIDCController extends PuterController {
|
||||
const resolved = await this.#resolveOrCreateOIDCUser(
|
||||
provider,
|
||||
userinfo,
|
||||
(stateDecoded.referrer as string) ?? null,
|
||||
);
|
||||
if ('error' in resolved) {
|
||||
return res.redirect(
|
||||
@@ -436,6 +447,7 @@ if (window.opener) {
|
||||
async #resolveOrCreateOIDCUser(
|
||||
provider: string,
|
||||
userinfo: { sub: string; email?: unknown; [k: string]: unknown },
|
||||
referrer?: string | null,
|
||||
): Promise<
|
||||
| { error: string }
|
||||
| {
|
||||
@@ -480,6 +492,7 @@ if (window.opener) {
|
||||
const outcome = await this.services.oidc.createUserFromOIDC(
|
||||
provider,
|
||||
userinfo as { sub: string; email?: string },
|
||||
referrer,
|
||||
);
|
||||
if (!outcome.success || !outcome.user) {
|
||||
return { error: outcome.error ?? 'Account creation failed.' };
|
||||
|
||||
@@ -360,6 +360,7 @@ export class OIDCService extends PuterService {
|
||||
async createUserFromOIDC(
|
||||
providerId: string,
|
||||
claims: OIDCUserInfo,
|
||||
referrer?: string | null,
|
||||
): Promise<{ success: boolean; user?: UserRow; error?: string }> {
|
||||
if (claims.email_verified === false) {
|
||||
return {
|
||||
@@ -479,7 +480,7 @@ export class OIDCService extends PuterService {
|
||||
signup_user_agent: req?.headers?.['user-agent'] ?? null,
|
||||
signup_origin: req?.headers?.origin,
|
||||
signup_server: this.config.serverId,
|
||||
referrer: req?.body?.referrer ?? null,
|
||||
referrer: referrer ?? null,
|
||||
});
|
||||
|
||||
if (!created) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
//# sourceMappingURL=FSEntry.js.map
|
||||
@@ -397,6 +397,10 @@ async function UIWindowLogin (options) {
|
||||
$(el_window).find(btnClass).css('display', 'flex');
|
||||
$(el_window).find(btnClass).on('click', function () {
|
||||
let url = `${window.gui_origin}/auth/oidc/${provider}/start?flow=login`;
|
||||
const referrer = options.referrer ?? window.referrerStr;
|
||||
if ( referrer ) {
|
||||
url += `&referrer=${encodeURIComponent(referrer)}`;
|
||||
}
|
||||
if ( window.embedded_in_popup && window.url_query_params?.get('msg_id') ) {
|
||||
url += `&embedded_in_popup=true&msg_id=${encodeURIComponent(window.url_query_params.get('msg_id'))}`;
|
||||
if ( window.openerOrigin ) {
|
||||
|
||||
@@ -178,6 +178,10 @@ function UIWindowSignup (options) {
|
||||
$(el_window).find(btnClass).css('display', 'flex');
|
||||
$(el_window).find(btnClass).on('click', function () {
|
||||
let url = `${window.gui_origin}/auth/oidc/${provider}/start?flow=signup`;
|
||||
const referrer = options.referrer ?? window.referrerStr;
|
||||
if ( referrer ) {
|
||||
url += `&referrer=${encodeURIComponent(referrer)}`;
|
||||
}
|
||||
if ( window.embedded_in_popup && window.url_query_params?.get('msg_id') ) {
|
||||
url += `&embedded_in_popup=true&msg_id=${encodeURIComponent(window.url_query_params.get('msg_id'))}`;
|
||||
if ( window.openerOrigin ) {
|
||||
|
||||
Reference in New Issue
Block a user