forked from USEPA/Public_Web_AppBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3adb1a
commit 2213629
Showing
3 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
|
||
/* | ||
Entry point for EPA authentication -- This authenticator looks to see if caller | ||
is already authenticated using the EPAOSC_Token given in the QueryString part | ||
of the URL. If the token is not valid or does not exist then redirect back | ||
to the EPAOSC login page. If it is valid then simply allow the deferred to | ||
resolve OK | ||
Date Who Description | ||
==================================================================================== | ||
053015 DPlume Initial implementation. | ||
060215 DPlume Added code to process GetString session id | ||
062415 DPlume Converted to ExtJs | ||
062915 DPlume Cleanup and add comments | ||
120215 DPlume Copied from R5 and adapted to R7 | ||
*/ | ||
|
||
|
||
var r7AuthMod = (function () { | ||
|
||
//Public Methods: | ||
return { | ||
|
||
Authenticate2: function (pDeferred) { | ||
|
||
try { | ||
|
||
var $j = jQuery.noConflict(); | ||
var sValidTokenUrl = "https://www.epaosc.org/svc/auth/ValidateToken.ashx?EPAOSC_Token="; | ||
|
||
// Get the querystring Parameters. Remove the ? | ||
var params = parseQueryString(location.search.replace("?", "")); | ||
|
||
// ServiceStatus < 0 indicates the call to the service is incomplete. 0 indicates Cancel, > 0 indicates the service has executed, See Result for success or failure) | ||
var _sAuthResult = { ServiceStatus: -1, ServiceResult: "NOTOPEN", bIsAuth: false }; | ||
|
||
if (typeof params.EPAOSC_Token != 'undefined') | ||
{ | ||
|
||
sValidTokenUrl += params.EPAOSC_Token; | ||
var $j = jQuery.noConflict(); | ||
|
||
//Call the EPAOSC Token Validation Service: | ||
|
||
$j.ajax({ | ||
type: "GET", | ||
url: sValidTokenUrl, | ||
error: function (o) { | ||
|
||
//Create and Show the authentication form. | ||
//alert("Error calling token validation service, Token: " + sEpaToken); | ||
|
||
console.log("EPAOSC TOKEN: " + params.EPAOSC_Token + "ERROR Calling Authenticate Service"); | ||
|
||
_sAuthResult = { ServiceStatus: -1, ServiceResult: "ERROR1", bIsAuth: false }; | ||
pDeferred.resolve(_sAuthResult); | ||
|
||
}, | ||
success: function (jData) { | ||
|
||
var sResult = JSON.stringify(jData) | ||
|
||
if ((sResult.toLowerCase().indexOf("true") > -1)) { | ||
|
||
|
||
_sAuthResult = { ServiceStatus: 1, ServiceResult: "OK", bIsAuth: true }; | ||
pDeferred.resolve(_sAuthResult); | ||
|
||
console.log("EPAOSC TOKEN: " + params.EPAOSC_Token + "OK"); | ||
} | ||
else { | ||
|
||
|
||
console.log("EPAOSC TOKEN: " + params.EPAOSC_Token + "NOT VALID, redirect"); | ||
|
||
_sAuthResult = { ServiceStatus: -1, ServiceResult: "NOTVALID", bIsAuth: false }; | ||
pDeferred.resolve(_sAuthResult); | ||
|
||
} | ||
|
||
} //End Success | ||
|
||
}); // End Ajax | ||
|
||
|
||
} //End if undefined | ||
else | ||
{ | ||
_sAuthResult = { ServiceStatus: -1, ServiceResult: "NOTOKEN", bIsAuth: false }; | ||
pDeferred.resolve(_sAuthResult); | ||
|
||
console.log("NO EPAOSC TOKEN"); | ||
|
||
}// End if else undefined | ||
|
||
} | ||
catch (ex) { | ||
|
||
console.log("Program ERROR: " + ex.message); | ||
|
||
_sAuthResult = { ServiceStatus: -1, ServiceResult: "ERROR2", bIsAuth: false }; | ||
pDeferred.resolve(_sAuthResult); | ||
|
||
} | ||
|
||
} // End Authenticate | ||
|
||
}; // End Return Public Methods | ||
|
||
function parseQueryString(queryString) { | ||
|
||
var params = {}, queries, temp, i, l; | ||
|
||
try { | ||
//http://www.joezimjs.com/javascript/3-ways-to-parse-a-query-string-in-a-url/ | ||
|
||
// Split into key/value pairs | ||
queries = queryString.split("&"); | ||
|
||
// Convert the array of strings into an object | ||
for (i = 0, l = queries.length; i < l; i++) { | ||
temp = queries[i].split('='); | ||
params[temp[0]] = temp[1]; | ||
} | ||
|
||
return params; | ||
} | ||
catch (ex) { | ||
return params; | ||
} | ||
|
||
}; //End parseQueryString | ||
|
||
|
||
})(); // End Module | ||
|
149 changes: 149 additions & 0 deletions
149
widgets/R7Validate_120215_1142/R7ValidateCredentials.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
This function is inserted into a WAB startup and provides the framework to authenticate | ||
and allow the WAB to continue or bailout. | ||
Wait for the API to be loaded then call validate credentials and wait via a pDeferred for either | ||
success or cancel. | ||
For a WAB do the following steps. | ||
1) Extract the files from the R7Validate_MMDDYY.zip. | ||
2) Copy R7AuthMod.js and R7ValidateCredentials.js files to the WAB root folder. | ||
3) In the WAB root folder open the index.html file and insert the following | ||
references to the files extracted in Step 1. These are inserted into the Body | ||
section AFTER simpleloader.js and BEFORE init.js. | ||
<script type="text/javascript" src="simpleLoader.js"></script> | ||
<!--The following two modules handle some simple authentication | ||
calling the EPA_OSC Token validation service. These modules expect | ||
a valid token on startup - if the token is not present or valid | ||
the flow redirects to the EPA OSC login with a call back url.--> | ||
<script type="text/javascript" src="R7AuthMod.js"></script> | ||
<script type="text/javascript" src="R5ValidateCredentials.js"></script> | ||
<script type="text/javascript" src="init.js"></script> | ||
4) Add the jQuery library to the HEAD of the WAB index.html | ||
<script type="text/javascript" src="http://r7.ercloud.org/jsapis/jquery/jquery-1.11.3.min.js"></script> | ||
5) Update R7ValidateCredentials.js to specify the EPAOSC Site ID as appropriate for this WAB. | ||
The Site ID is the EPAOSC numeric identifier for each site. This value is used to compose a callback URL. | ||
Date Who Description | ||
==================================================================================== | ||
053015 DPlume Initial implementation. | ||
060215 DPlume Modified to adapt to R5Auth using URL String. | ||
062415 DPlume Converted to ExtJs. | ||
062915 DPlume Updated instructions and filenames. | ||
120215 DPlume Copied from R5 version and adapted to R7. | ||
*/ | ||
|
||
(function waitForAPI() { | ||
|
||
|
||
if (typeof require === 'undefined') { | ||
|
||
if (window.console) { | ||
console.log('Waiting for API to be loaded.'); | ||
} | ||
setTimeout(waitForAPI, 100); | ||
return; | ||
} | ||
else { | ||
|
||
validateCredentials(); | ||
} | ||
|
||
function validateCredentials() { | ||
require([ | ||
'dojo/aspect', | ||
'dojo/Deferred', | ||
'jimu/utils'], | ||
|
||
function (aspect, Deferred, jimuUtils) { | ||
|
||
aspect.around(jimuUtils, 'createWebMap', function (originalMethod) { | ||
|
||
return function (portalUrl, itemId, mapDiv, options) { | ||
|
||
var mapDeferred = new Deferred(); | ||
var authDefer = new Deferred(); | ||
var authResult = null; | ||
|
||
// Set up the authorization deferrer: | ||
authDefer.then( | ||
|
||
//Callback after resolution of the deferrer. authResult is a record. | ||
function (authResult) { | ||
|
||
//ServiceStatus < 0 indicates the call to the service is incomplete. 0 indicates Cancel, > 0 indicates the service has executed, See Result for success or failure) | ||
//authResult = { ServiceStatus: N, ServiceResult: "STRING", bIsAuth: Bool}; | ||
|
||
if (authResult.bIsAuth) { | ||
|
||
// Simply allow the WAB to start | ||
originalMethod.call(jimuUtils, portalUrl, itemId, mapDiv, options).then(function (deferred) { | ||
mapDeferred.resolve(deferred); | ||
return; | ||
}); | ||
|
||
} | ||
else { | ||
try { | ||
|
||
//====================================================== | ||
//Called on Error or Invalid token -- simply refer back to the | ||
//EPAOSC login. | ||
|
||
mapDeferred.reject(); | ||
|
||
// ================================================================ | ||
// WAB INSTALL: | ||
// Update the site ID here, it is used to build the call back URL | ||
// ================================================================ | ||
|
||
var sSiteId = "11265" | ||
var sLoginUrl = "https://www.epaosc.org/site/login.aspx?ReturnURL=/site/map_list.aspx/?site_id=" + sSiteId; | ||
//================================================================ | ||
|
||
//alert("Redirecting back to EPAOSC login.") | ||
console.log("Redirecting back to: " + sLoginUrl) | ||
window.location.replace(sLoginUrl); | ||
|
||
} | ||
catch (ex) { | ||
alert("validateCredentials error: " + ex.message) | ||
} | ||
|
||
} // End authResult.bIsAuth | ||
} | ||
|
||
); // End authDefer | ||
|
||
// ================================================= | ||
// Call this with authDefer and wait for resolution | ||
|
||
$(document).ready(function () { | ||
|
||
r7AuthMod.Authenticate2(authDefer); | ||
|
||
}); | ||
|
||
return mapDeferred; | ||
|
||
}; | ||
}); | ||
}); | ||
|
||
} // End Function validateCredentials | ||
|
||
})(); |
Binary file not shown.