mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Implement DiscourseConnect to enable easy sign-in to community forum
Summary: - Update cookie module, to support modern sameSite settings - Add a new cookie, grist_sid_status with less-sensitive value, to let less-trusted subdomains know if user is signed in - The new cookie is kept in-sync with the session cookie. - For a user signed in once, allow auto-signin is appropriate. - For a user signed in with multiple accounts, show a page to select which account to use. - Move css stylings for rendering users to a separate module. Test Plan: Added a test case with a simulated Discourse page to test redirects and account-selection page. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3047
This commit is contained in:
@@ -100,22 +100,6 @@ export function initGristSessions(instanceRoot: string, server: GristServer) {
|
||||
const sessionStoreCreator = createSessionStoreFactory(sessionsDB);
|
||||
const sessionStore = sessionStoreCreator();
|
||||
|
||||
const adaptDomain = process.env.GRIST_ADAPT_DOMAIN === 'true';
|
||||
const fixedDomain = process.env.GRIST_SESSION_DOMAIN || process.env.GRIST_DOMAIN;
|
||||
|
||||
const getCookieDomain = (req: express.Request) => {
|
||||
const mreq = req as RequestWithOrg;
|
||||
if (mreq.isCustomHost) {
|
||||
// For custom hosts, omit the domain to make it a "host-only" cookie, to avoid it being
|
||||
// included into subdomain requests (since we would not control all the subdomains).
|
||||
return undefined;
|
||||
}
|
||||
if (adaptDomain) {
|
||||
const reqDomain = parseSubdomain(req.get('host'));
|
||||
if (reqDomain.base) { return reqDomain.base.split(':')[0]; }
|
||||
}
|
||||
return fixedDomain;
|
||||
};
|
||||
// Use a separate session IDs for custom domains than for native ones. Because a custom domain
|
||||
// cookie could be stolen (with some effort) by the custom domain's owner, we limit the damage
|
||||
// by only honoring custom-domain cookies for requests to that domain.
|
||||
@@ -148,5 +132,23 @@ export function initGristSessions(instanceRoot: string, server: GristServer) {
|
||||
|
||||
const sessions = new Sessions(sessionSecret, sessionStore);
|
||||
|
||||
return {sessions, sessionSecret, sessionStore, sessionMiddleware, sessionStoreCreator};
|
||||
return {sessions, sessionSecret, sessionStore, sessionMiddleware};
|
||||
}
|
||||
|
||||
export function getCookieDomain(req: express.Request) {
|
||||
const mreq = req as RequestWithOrg;
|
||||
if (mreq.isCustomHost) {
|
||||
// For custom hosts, omit the domain to make it a "host-only" cookie, to avoid it being
|
||||
// included into subdomain requests (since we would not control all the subdomains).
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const adaptDomain = process.env.GRIST_ADAPT_DOMAIN === 'true';
|
||||
const fixedDomain = process.env.GRIST_SESSION_DOMAIN || process.env.GRIST_DOMAIN;
|
||||
|
||||
if (adaptDomain) {
|
||||
const reqDomain = parseSubdomain(req.get('host'));
|
||||
if (reqDomain.base) { return reqDomain.base.split(':')[0]; }
|
||||
}
|
||||
return fixedDomain;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user