Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't clear oAuth2 session on restart #2701

16 changes: 14 additions & 2 deletions packages/insomnia-app/app/network/o-auth-2/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ import electron from 'electron';
import * as uuid from 'uuid';
import querystring from 'querystring';

const AUTH_WINDOW_SESSION_ID = uuid.v4();
const LOCALSTORAGE_KEY_SESSION_ID = 'insomnia::current-oauth-session-id';
KarolineKarkosch marked this conversation as resolved.
Show resolved Hide resolved
let authWindowSessionId = `oauth2_${uuid.v4()}`;

if (window.localStorage.getItem(LOCALSTORAGE_KEY_SESSION_ID)) {
authWindowSessionId = window.localStorage.getItem(LOCALSTORAGE_KEY_SESSION_ID);
} else {
window.localStorage.setItem(LOCALSTORAGE_KEY_SESSION_ID, authWindowSessionId);
}

export function clearOAuthSession() {
authWindowSessionId = `oauth2_${uuid.v4()}`;
window.localStorage.setItem(LOCALSTORAGE_KEY_SESSION_ID, authWindowSessionId);
}

export function responseToObject(body, keys, defaults = {}) {
let data = null;
Expand Down Expand Up @@ -72,7 +84,7 @@ export function authorizeUserInWindow(
const child = new electron.remote.BrowserWindow({
webPreferences: {
nodeIntegration: false,
partition: `oauth2_${AUTH_WINDOW_SESSION_ID}`,
partition: authWindowSessionId,
},
show: false,
});
Expand Down
6 changes: 6 additions & 0 deletions packages/insomnia-app/app/ui/components/settings/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { setFont } from '../../../plugins/misc';
import * as session from '../../../account/session';
import Tooltip from '../tooltip';
import CheckForUpdatesButton from '../check-for-updates-button';
import { clearOAuthSession } from '../../../network/o-auth-2/misc';

// Font family regex to match certain monospace fonts that don't get
// recognized as monospace
Expand Down Expand Up @@ -477,6 +478,11 @@ class General extends React.PureComponent<Props, State> {
{ placeholder: '~/.insomnia:/other/path' },
)}

<hr className="pad-top" />
<h2>Clear OAuth2 Session</h2>
<button className="btn btn--clicky" onClick={clearOAuthSession}>
Clear session
</button>
KarolineKarkosch marked this conversation as resolved.
Show resolved Hide resolved
<br />

<hr className="pad-top" />
Expand Down