Skip to content

Commit

Permalink
[FIX] OAuth Login not working on Firefox (#20722)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
  • Loading branch information
gabriellsh and ggazzo authored Feb 12, 2021
1 parent 78b972b commit 35171fa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/custom-oauth/client/custom_oauth_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Random } from 'meteor/random';
import { ServiceConfiguration } from 'meteor/service-configuration';
import { OAuth } from 'meteor/oauth';
import s from 'underscore.string';
import './swapSessionStorage';

import { isURL } from '../../utils/lib/isURL';

Expand Down
42 changes: 42 additions & 0 deletions app/custom-oauth/client/swapSessionStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Meteor } from 'meteor/meteor';
import { OAuth } from 'meteor/oauth';
import { Reload } from 'meteor/reload';

// TODO: This is a nasty workaround and should be removed as soon as possible
// Firefox is losing the sessionStorage data (v >= 79.0) after the redirect

if (navigator.userAgent.indexOf('Firefox') !== -1) {
const KEY_NAME = 'Swapped_Storage_Workaround';

OAuth.saveDataForRedirect = (loginService, credentialToken) => {
Meteor._localStorage.setItem(KEY_NAME, JSON.stringify({ loginService, credentialToken }));
Reload._migrate(null, { immediateMigration: true });
};

OAuth.getDataAfterRedirect = () => {
let migrationData = Meteor._localStorage.getItem(KEY_NAME);
Meteor._localStorage.removeItem(KEY_NAME);
try {
migrationData = JSON.parse(migrationData);
} catch (error) {
migrationData = null;
}

if (! (migrationData && migrationData.credentialToken)) { return null; }

const { credentialToken } = migrationData;
const key = OAuth._storageTokenPrefix + credentialToken;
let credentialSecret;
try {
credentialSecret = sessionStorage.getItem(key);
sessionStorage.removeItem(key);
} catch (e) {
Meteor._debug('error retrieving credentialSecret', e);
}
return {
loginService: migrationData.loginService,
credentialToken,
credentialSecret,
};
};
}

0 comments on commit 35171fa

Please sign in to comment.