Skip to content

Commit

Permalink
SamlConfig: new utility function, _processInitialRequest
Browse files Browse the repository at this point in the history
The logic handling the case where we are given a relay state or not
and what that relay state might contain has gotten a bit fiddly. Let's
factor it out into its own function.
  • Loading branch information
jordigh committed Jan 31, 2025
1 parent 3f97771 commit b6a9182
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/server/lib/SamlConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,44 @@ export class SamlConfig {
}));
}

private async _processInitialRequest(req: express.Request) {
const relayState: string = req.body.RelayState;
const sessionId = this._gristServer.getSessions().getSessionIdFromRequest(req) || undefined;
const params = {
sessionId,
redirectUrl: "",
unsolicited: true,
action: "",
};

if (!relayState) {
// Presumably an IdP-inititated signin.
params.redirectUrl = getOriginUrl(req);
params.action = "login";
return params;
}

const permitStore = this._gristServer.getExternalPermitStore();
const state = await permitStore.getPermit(relayState);
if (!state) {
// Presumably an IdP-inititated signin without a permit, but
// let's check to see if it has a redirect URL.
params.redirectUrl = checkRedirectUrl(relayState, req).href;
params.action = "login";
return params;
}

params.unsolicited = false;

await permitStore.removePermit(relayState);
// Trust this URL because it could only have come from us (i.e. we should've checked it
// earlier if it was untrusted).
params.redirectUrl = state.url!;
params.sessionId = state.sessionId;
params.action = state.action || "";
return params;
}

/**
*
* Login and logout involves redirecting to a SAML IdP, which will then POST some information
Expand Down

0 comments on commit b6a9182

Please sign in to comment.