var cred = "esri_jsapi_id_manager_data"; function init() { loadCredentials(); //see if cred. already exists for this session esri.config.defaults.io.proxyUrl = "proxy.php"; esri.config.defaults.io.alwaysUseProxy = false; var process = function(ref) { var def = new dojo.Deferred(); if (ref != "" && esri.id.credentials.length == 0) { var refToken = esri.request({ url : "https://gis.ourdomain/arcgis/", //any url that's proxied in proxy content : { ref : ref }, handleAs : "json" }); function success(res) { var idObject, idJson; if (res.token != 'noToken') { var serverInfo = { "server" : "https://gis.ourdomain.com", "tokenServiceUrl" : "https://gis.ourdomain.com/arcgis/tokens/", "currentVersion" : 10.11 }; var securedServices = []; //i guess this doesn't have to be a complete list securedServices.push("https://gis.ourdomain.com/arcgis/folder/MapServer/0"); var creationTime = (new Date).getTime(); var idString = dojo.toJson({ "serverInfos" : [serverInfo], "credentials" : [{ "userId" : 'auser', //user that was hard coded "server" : serverInfo.server, "token" : res.token, "expires" : res.expires, "ssl" : false, "creationTime" : creationTime, "resources" : securedServices }] }); if (supports_local_storage()) { // use local storage window.localStorage.setItem(cred, idString); idJson = window.localStorage.getItem(cred); } else { // use a cookie dojo.cookie(cred, idString, { expires : 1 }); idJson = dojo.cookie(cred); } if (idJson && idJson != "null" && idJson.length > 4) { //load the credential idObject = dojo.fromJson(idJson); esri.id.initialize(idObject); } def.callback("loaded"); } else { def.callback("not loaded"); //proxy didn't return token for 1 reason or other } } refToken.then(success); } else { def.callback("not loaded"); //no referrer or already logged in } return def; } var ref = document.referrer; process(ref).then(function(response) { //continue adding layers, ect... }) }
$targetUrl = $_SERVER['QUERY_STRING']; $parts = preg_split("/\?/", $targetUrl); $targetPath = $parts[0]; $qStringArr = array(); parse_str($parts[1],$qStringArr); // open the curl session $session = curl_init(); if(array_key_exists('ref', $qStringArr) && $qStringArr['ref'] != ''){ //esri.request call with referrer if($qStringArr['ref'] == 'https://theReferrer.com/imLookingFor.html'){ $data = array( 'username' => 'auser', 'password' => 'auserpassword', 'client' => 'ip', //for dev only, switch to http referr on production 'ip' => '123.123.22.41', 'expiration' => '60', 'f' => 'json' ); $postData = http_build_query($data); $targetUrl = "https://gis.ourdomain/arcgis/tokens/generateToken"; } else{//referrer didnt match, return junk response echo json_encode(array('token'=>'noToken')); exit; } } else{ //continue w/ normal proxy call $postData = file_get_contents("php://input"); } //omitted cURL options array $response = curl_exec($session); echo $response;
function init(){ esri.config.defaults.io.proxyUrl = "proxy.php"; var ref = document.referer; var request = esri.request({ url:window.location.href, content:{ ref:ref }, handleAs:"json" },{useProxy:true}); function suc(response){ var idString = dojo.toJson({ "serverInfos": [serverInfo], "credentials": [{ "userId": rahul, "server": "http://myserver:8399", "token": this.token, "expires": this.expires, "ssl": false, "creationTime": creationTime, "resources": securedServices }] }); // store it client side if (_supports_local_storage()) { window.localStorage.setItem(this.token._jsAPIIDManagerData, idString); } else { dojo.cookie(this.token._jsAPIIDManagerData, idString, { expires: 1 }); } loadcredentials(); } function err(response){ console.log('response'); } request.then(suc,err); }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.