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

Have made cross origin login fix #302

Merged
merged 2 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,7 @@ require('../css/app.css');
Bluebird.config({ warnings: { wForgottenReturn: false } });
window['encoding-indexes'] = {"windows-1252": WINDOWS_1252};

/* IMPORTANT:
* we have to set the public path here to include any potential prefix
* has to happen before the bootstrap!
*/
let req = window.INITIAL_REQUEST_PARAMS || {};
let is_dev_server = false;
// #if process.env.NODE_ENV === 'dev-server'
is_dev_server = true;
// #endif
if (!is_dev_server) {
let prefix =
typeof req[URI_PREFIX] === 'string' ?
Misc.prepareURI(req[URI_PREFIX]) : "";
__webpack_public_path__ = prefix + '/static/' + PLUGIN_NAME + '/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, it seems like you've stripped things out regarding for when dev_server is true which seems safe enough, but isn't this clause for the non-dev_server case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand all of the use cases here, but as far as I can see, this code was hard-coded NOT to run (since is_dev_server = true; came right before that if).
So I don't know when that code has ever run.
It's only job is to set __webpack_public_path__ .Webpack dev server isn't used in production. Webpack is used to package the JS bundle, but we've been doing that a lot without this code, so I can only assume this isn't needed in our current workflows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgh. Thanks for the cleanup 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #142 for the introduction of this.

}

/**
* IViewer bootstrap function
Expand All @@ -62,7 +48,6 @@ if (!is_dev_server) {
bootstrap(function(aurelia) {
aurelia.use.basicConfiguration();
let ctx = new Context(aurelia.container.get(EventAggregator), req);
if (is_dev_server) ctx.is_dev_server = true;
aurelia.container.registerInstance(Context,ctx);

aurelia.start().then(
Expand Down
24 changes: 2 additions & 22 deletions src/viewers/viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ import {noModifierKeys, primaryAction} from 'ol/events/condition';
import Draw from './interaction/Draw';
import ShapeEditPopup from './controls/ShapeEditPopup';
import {checkAndSanitizeServerAddress,
isSameOrigin,
sendRequest,
makeCrossDomainLoginRedirect} from './utils/Net';
sendRequest} from './utils/Net';
import {generateRegions} from './utils/Regions';
import {modifyStyles,
updateStyleFunction} from './utils/Style';
Expand Down Expand Up @@ -186,20 +184,6 @@ class Viewer extends OlObject {
*/
this.sync_group_ = null;

/**
* a flag that's only relevant if the server is not same orgin.
* then we have to go different ways to redirect the user to the server login.
* this flag reminds us if we've done so or still need to do so, i.e. if we
* have a supposed session or not.
*
* @type {boolean}
* @private
*/
this.haveMadeCrossOriginLogin_ = isSameOrigin(this.server_) ? true : false;
if (!this.haveMadeCrossOriginLogin_ &&
window['location']['href'].indexOf("haveMadeCrossOriginLogin_") !== -1)
this.haveMadeCrossOriginLogin_ = true;

/**
* the id of the element serving as the container for the viewer
* @type {string}
Expand Down Expand Up @@ -364,11 +348,7 @@ class Viewer extends OlObject {
};

// execute initialization function
// for cross domain we check whether we need to have a login made, otherwise
// we redirect to there ...
if (isSameOrigin(this.server_) || this.haveMadeCrossOriginLogin_) {
this.initialize_();
} else makeCrossDomainLoginRedirect(this.server_);
this.initialize_();
}

/**
Expand Down
31 changes: 0 additions & 31 deletions src/viewers/viewer/utils/Net.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,37 +406,6 @@ export const sendSameOrigin = function(
xhr.send(method === 'POST' ? content : null);
}

/**
* Redirects to another domain for login to then be redirected and able
* to make more requests cross-domain with a working session
*
* @private
* @static
* @function
* @param {Object} server the server info as an object
*/
export const makeCrossDomainLoginRedirect = function(server) {
if (typeof(server) !== 'object' || typeof(server['full']) !== 'string')
return;

// that's where we'd like to come back to after redirect
var oldHref = window.location.href;
// check if out old href had a query string in it, then we need to append our
// own flag to be returned to us
var appendFlagWithAmpersand = false;
if (oldHref.indexOf("?") !== -1)
appendFlagWithAmpersand = true;

var newLocation =
server['full'] + "/webclient/login/?url=" + oldHref;
// we append the flag to know that we have been there
if (appendFlagWithAmpersand)
newLocation += "&";
else newLocation += "?";

window.location.href = newLocation + "haveMadeCrossOriginLogin_";
}

/**
* Sends an ajax request using jsonp - useded internally!
*<p>NOTE: Use [sendRequest]{@link utils#sendRequest} instead!</p
Expand Down