(core) Remove LoginSession, which was mainly serving situations that are no longer used.

Summary:
In the past, Cognito sign-ins were intended to give authorization to some AWS
services (like SQS); various tokens were stored in the session for this
purpose. This is no longer used. Profiles from Cognito now serve a limited
purpose: first-time initialization of name and picture, and keeping track of
which login method was used. For these remaining needs, ScopedSession is
sufficient.

Test Plan:
Existing test pass. Tested manually that logins work with Google and
Email + Password. Tested manually that on a clean database, name and picture
are picked up from a Google Login.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D2907
This commit is contained in:
Dmitry S
2021-07-12 12:10:04 -04:00
parent f079ffdcb3
commit 869b2f00ec
14 changed files with 95 additions and 132 deletions

View File

@@ -1,17 +1,10 @@
import {ScopedSession} from 'app/server/lib/BrowserSession';
import * as Comm from 'app/server/lib/Comm';
import {GristServer} from 'app/server/lib/GristServer';
import {cookieName, SessionStore} from 'app/server/lib/gristSessions';
import {ILoginSession} from 'app/server/lib/ILoginSession';
import * as cookie from 'cookie';
import * as cookieParser from 'cookie-parser';
import {Request} from 'express';
interface Session {
scopedSession: ScopedSession;
loginSession?: ILoginSession;
}
/**
*
* A collection of all the sessions relevant to this instance of Grist.
@@ -21,8 +14,7 @@ interface Session {
* from code related to websockets.
*
* The collection caches all existing interfaces to sessions.
* LoginSessions play an important role in standalone Grist and address
* end-to-end sharing concerns. ScopedSessions play an important role in
* ScopedSessions play an important role in
* hosted Grist and address per-organization scoping of identity.
*
* TODO: now this is separated out, we could refactor to share sessions
@@ -32,7 +24,7 @@ interface Session {
*
*/
export class Sessions {
private _sessions = new Map<string, Session>();
private _sessions = new Map<string, ScopedSession>();
constructor(private _sessionSecret: string, private _sessionStore: SessionStore, private _server: GristServer) {
}
@@ -41,7 +33,7 @@ export class Sessions {
* Get the session id and organization from the request, and return the
* identified session.
*/
public getOrCreateSessionFromRequest(req: Request): Session {
public getOrCreateSessionFromRequest(req: Request): ScopedSession {
const sid = this.getSessionIdFromRequest(req);
const org = (req as any).org;
if (!sid) { throw new Error("session not found"); }
@@ -51,29 +43,16 @@ export class Sessions {
/**
* Get or create a session given the session id and organization name.
*/
public getOrCreateSession(sid: string, domain: string, userSelector: string): Session {
public getOrCreateSession(sid: string, domain: string, userSelector: string): ScopedSession {
const key = this._getSessionOrgKey(sid, domain, userSelector);
if (!this._sessions.has(key)) {
const scopedSession = new ScopedSession(sid, this._sessionStore, domain, userSelector);
this._sessions.set(key, {scopedSession});
this._server.create.adjustSession(scopedSession);
this._sessions.set(key, scopedSession);
}
return this._sessions.get(key)!;
}
/**
* Access a LoginSession interface, creating it if necessary. For creation,
* purposes, Comm, and optionally InstanceManager objects are needed.
*
*/
public getOrCreateLoginSession(sid: string, domain: string, comm: Comm,
userSelector: string): ILoginSession {
const sess = this.getOrCreateSession(sid, domain, userSelector);
if (!sess.loginSession) {
sess.loginSession = this._server.create.LoginSession(comm, sid, domain, sess.scopedSession);
}
return sess.loginSession;
}
/**
* Returns the sessionId from the signed grist cookie.
*/