I'm attempting to use Adobe's Digital Publishing Suite Web Viewer. I've set up my Web Viewer correctly - it is working within my website. However, it is not authenticating that each user has access to the folio that the Web Viewer is accessing. Adobe has a sort of documentation on how to do this, but their documentation seems lacking. It seems as if Adobe is asking me to get users' username and password to Adobe - but that can't be right. I doubt Adobe would invite phising. But that isn't the only point I'm lost on.
My current script is as follows:
var wvQueryParamGroups = location.search.match(/[?&^#]wv=(s[\/%\-.\w]+)/),
wvQueryParam = wvQueryParamGroups && wvQueryParamGroups.length === 2 ? decodeURIComponent(wvQueryParamGroups[1]) : null;
function loadXMLDoc(url, successCallback, failCallback) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlhttp.responseText, "application/xml");
successCallback(xmlDoc);
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 0) {
alert("unsuccessful cross-domain data access attempt?");
failCallback(xmlhttp.status);
} else if (xmlhttp.readyState == 4) {
failCallback(xmlhttp.status);
} else {
console.log('readystate=' + xmlhttp.readyState + ', status=' + xmlhttp.status);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function directEntitlementSignIn(directEntitlementURL, emailAddress, password, appID, authTokenSuccess, authTokenFail) {
var response;
if (!authTokenSuccess || !authTokenFail) {
throw new Error('Callbacks are required: ');
}
loadXMLDoc(directEntitlementURL + '?emailAddress=' + emailAddress + '&password=' + password + '&appId=' + appID,
handleToken = function (data) {
token = data.documentElement.childNodes[0].innerHTML;
authTokenSuccess(token);
}
);
}
function onAuthTokenSuccess(token) {
alert(token);
// pass the token into the Authenticator class's login method
}
function onAuthTokenFail(status) {
alert("fail: " + status);
// prompt the user to try logging in again
}
function signIn(emailAddress, password) {
var deAPIURL = 'http://127.0.0.1/hostDemos r27/authHard/test.php';
var emailAddress; // user's login ID.....get from form
var password; // user's password ... get from form
var appID = 'com.publisher.magazine';
directEntitlementSignIn(deAPIURL, emailAddress, password, appID, onAuthTokenSuccess, onAuthTokenFail);
}
function eventCallback(ev) {
if (ev.eventType == "paywall") {
return false;
}
if (ev.eventType == "metadata") {
return true;
}
console.log(ev);
return true;
}
function errorCallback (message) {
console.log(message);
return true;
}
function redirectCallbackHandler (message) {
console.log(message);
}
var wv_appName = "Professional Roofing";
var wv_accountID = Account_ID_Is_Here; //Hiding account ID purposely
var wv_folio = "August 2014 Issue";
var wv_article = "Cover";
var wv_url = '/s/' + wv_appName + '/' + wv_accountID + '/' + wv_folio + '/' + wv_article + '.html';
console.log(wv_url);
var bridge = adobeDPS.frameService.createFrame({
boolIsFullScreen : true,
parentDiv : 'mainContainer',
wrapperClasses : 'uniqueFrame',
iframeID : 'demoFrame',
accountIDs : wv_accountID,
wvParam : wvQueryParam ? wvQueryParam : wv_url,
curtainClasses : 'mask hidden',
eventCallback : eventCallback,
errorCallback : errorCallback,
redirectCallback : redirectCallbackHandler
});
Adobe doesn't need your username and password, they need an authentication token.
To make it work you need:
Implement the Direct Entitlements API
Ask you account representative in Adobe to create an integrator id
After that you need to create an authenticator:
auth = adobeDPS.authenticationService.createAuthenticator(strAccountID, strIntegratorID);
And pass to it the authToken
auth.login(token, successCalck, errorCallback)
Related
this is my project: http://cryptotipsitalia.sytes.net/.
I want add Ethereum value down to "Valore BTC" with Node.js: https://www.npmjs.com/package/crypto-price.
How can I add it?
That's my code:
function getValueBTC() { <!-- chiamata API --> /
var xmlhttp = new XMLHttpRequest();
var url = "https://api.coindesk.com/v1/bpi/currentprice.json";
var output;
console.log(url);
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
output = this.responseText;
var obj = JSON.parse(output);
var rightValue = (obj.bpi.EUR.rate).substring(0,obj.bpi.EUR.rate.length-2); /* eliminazione ultime due cifre */
document.getElementById("cellaValoreBTC").innerHTML= obj.bpi.EUR.symbol + " " + rightValue;
}
};
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("Content-type", "text/plain");
xmlhttp.send();
}
let price = require('crypto-price');
price.getCryptoPrice('EUR', 'ETH').then(obj => {
console.log(obj.price); // It will print ETH rate per BTC
document.getElementById("cellaValoreETH").innerHTML = obj.price;
}).catch(err => {
console.log(err);
});
table><tr><td width="75%">VALORE BTC:</td></tr><tr id="cellaValoreBTC" width="75%"></tr><tr><td width="75%">VALORE ETH:</td></tr><tr id="cellaValoreETH" width="75%"></table>
Why "document.getElementById("cellaValoreBTC").innerHTML = obj.price;" doesnt' work?
How can I add obj.price in my HTML code?
Thanks
I need to simulate an authenticated user to pull a JSON file. I am using Last.fm's API, but there is currently no method to pull the specific data I want. If I just pull it as plain text in browser, it shows up. However, I want data that is specific to an authenticated user. So, if I login to Last.fm as me, then pull the data, the data is different than if I just pull the data from anywhere.
Basically, the data contained in this file is specific to the user, and as there is no function specifically set to access this file, I don't know how I'd do that....
My function that pulls the current data is listed below:
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
function getRadio() {
var trackUrls = new Array();
var resValue;
var station;
var radioStation;
var url;
var data;
var neatDisplay;
var resultsDisplay = document.getElementById('result');
var radioTypeInput = document.getElementsByName('radioType');
var queryInput = document.getElementById('query');
var query = queryInput.value;
for (var i = 0, length = radioTypeInput.length; i < length; i++) {
if (radioTypeInput[i].checked) {
station = radioTypeInput[i].value;
break;
}
}
if (station == 1) {
radioStation = "recommended";
} else if (station == 2) {
radioStation = "library";
} else if (station == 3) {
radioStation = "mix";
} else {
radioStation = "music";
};
if (radioStation != "music") {
url = "https://crossorigin.me/" + "http://www.last.fm/player/station/user/" + query + "/" + radioStation;
} else {
url = "https://crossorigin.me/" + "http://www.last.fm/player/station/music/" + query;
};
console.log(url);
request = createCORSRequest("get", url);
if (request) {
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
data = JSON.parse(request.responseText);
for (i = 0; i < data.playlist.length; i++) {
trackUrls[i] = data.playlist[i].playlinks[0].url;
}
neatDisplay = trackUrls.join("\n ");
resultsDisplay.innerHTML = neatDisplay;
console.log(neatDisplay.toString());
neatDisplay = neatDisplay.toString();
return neatDisplay.toString();
} else if (request.status == 503) {
resultsDisplay.innerHTML = "Connection Error. The application may be overloaded."
} else {}
};
request.onerror = function() {
document.getElementById("result").innerHTML = "Connection Error. The application may be overloaded. Try again later"
};
request.send();
}
}
Ultimately, this used to pull Spotify links in the resulting data, but now it pulls YouTube. So, the problem only occurs if just pulling the file, without authentication.
I am trying to develop a chrome extension which parses data from the current tab and post it to a url which does processing on the data. In certain cases the page may need to be redirected so that certain get parameters are present. My popup.js can successfully do the redirect, but I need to click on the extension a second time to get it to run properly. Note: it runs properly if the page has the correct parameters. How can I adjust this so that the code reruns after the redirect and posts the new source to the specified url.
Here is my popup.js:
var url = "";
chrome.runtime.onMessage.addListener(function(request, sender) {
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
url = tabs[0].url;
if (url.search("[?&]view=list") == -1)
{
url = setGetParameter(url,'view','list');
chrome.tabs.update(tabs[0].id,{url:url});
process(request);
}
});
process(request);
});
function process(request) {
if (request.action == "getSource") {
message.innerText = request.source;
var data = new FormData();
data.append('source',request.source);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == XMLHttpRequest.DONE) {
message.innerText = xhttp.responseText;
}
}
xhttp.open("POST","http://127.0.0.1:5000/api/scraper",true);
xhttp.send(data);
}
}
function onWindowLoad() {
var message = document.querySelector('#message');
chrome.tabs.executeScript(null, {
file: "getPagesSource.js"
}, function() {
// If you try and inject into an extensions page or the webstore/NTP you'll get an error
if (chrome.runtime.lastError) {
message.innerText = 'There was an error injecting script : \n' + chrome.runtime.lastError.message;
}
});
}
function setGetParameter(url, paramName, paramValue)
{
var hash = location.hash;
url = url.replace(hash, '');
if (url.indexOf(paramName + "=") >= 0)
{
var prefix = url.substring(0, url.indexOf(paramName));
var suffix = url.substring(url.indexOf(paramName));
suffix = suffix.substring(suffix.indexOf("=") + 1);
suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : "";
url = prefix + paramName + "=" + paramValue + suffix;
}
else
{
if (url.indexOf("?") < 0)
url += "?" + paramName + "=" + paramValue;
else
url += "&" + paramName + "=" + paramValue;
}
return url + hash;
}
window.onload = onWindowLoad;
Take a look at webRequest.onBeforeRedirect, this event fired when a redirect is about to be executed. You can listen to this event and do your logic again.
Don't forget to declare webRequest permission along with host permissions for any hosts whose network requests you want to access in you manifest.json.
I am downloading a file in my java application using jquery.
It is downloading in correct format in IE8 where as Format is getting changed when i am using IE10.
Here is my code, where I am setting hearder.
function converthtml() {
var CustomerID = document.getElementById('customerID').value;
var ci = document.getElementById("ci").value;
var strvar;
strvar = term.textContent || term.innerText;
strvar = encodeURIComponent(strvar);
var xmlHttp;
var xmlHttp;
var flag = 0;
if (typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp == null) {
alert("Browser does not support XMLHTTP Request");
return;
}
xmlHttp.onreadystatechange = stateChange2;
function stateChange2() {
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
//alert("response : "+xmlHttp.responseText);
alert("Session value saved successfuly");
}
}
var params = "sessiondata=" + strvar + "&ci=" + ci + "" + "&customerID=" + CustomerID;
xmlHttp.open("POST", "DownloadSession", true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send(params);
// xmlHttp.send("sessiondata="+strvar+"");
document.getElementById("downloadSession").disabled = false;
}
I suspect the following statement is causing the format change
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
Kindly suggest me an alternative that keeps content-type same across all the browser versions......
I'm trying post my JSON data to server but it fails when i submit the data. it gives me error code 403. i tried this method in ADT for android it worked. it's not working on titanium only.
Here's my code.
function postData() {
Ti.API.info("JSON Data :" + JSONStringData);
var url = "http://www.vrsweb.in/hotels/admin/ws/orderItems.php";
var xhrpost = Titanium.Network.createHTTPClient();
xhrpost.setTimeout(5000);
xhrpost.open('POST', url);
xhrpost.setRequestHeader("Content-Type", "application/json");
xhrpost.setRequestHeader('charset', 'utf-8');
xhrpost.setRequestHeader("enctype", "multipart/form-data");
xhrpost.send(JSONStringData);
xhrpost.onerror = function(e) {
Ti.API.debug(e.error);
if (platform == 'android') {
var toast = Titanium.UI.createNotification({
message : 'Cannot Connect to server please check your internet Connection!',
duration : Titanium.UI.NOTIFICATION_DURATION_SHORT
});
toast.show();
}
if (platform == 'iphone') {
alert('Cannot Connect to server please check your internet Connection!');
}
Ti.API.info("Status code :" + xhrpost.status);
};
xhrpost.onload = function() {
if (xhr.status == 200) {
Ti.API.info("XHR Status : " + xhrpost.status);
data = JSON.parse(this.responseText);
Ti.API.info("Response from server :" + data);
if (platform == 'android') {
var toast = Titanium.UI.createNotification({
message : 'Table booked Successfully!',
duration : Titanium.UI.NOTIFICATION_DURATION_SHORT
});
toast.show();
}
if (platform == 'iphone') {
alert('Table booked Successfully!');
}
} else {
Ti.API.info("XHR Status : " + xhrpost.status);
}
};
}
I don't understand what am i doing wrong.
And i am Collecting data through JSON Get Method from the server and adding it to array. Converting that array into JSON and posting it to server.
Here's how i get Order id from server and saving it to array.
aButton.addEventListener('click', function() {
name = textUser.value;
qty = textPass.value;
price = textConfirmPass.value;
type = textEmail.value;
var url = "http://vrsweb.in/hotels/admin/ws/placeOrder.php?tName=" + id + "&wName=" + logName;
var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(5000);
//xhr.autoEncodeUrl = false;
xhr.open('POST', url);
xhr.setRequestHeader('User-Agent', 'My User Agent');
xhr.send();
xhr.onerror = function(e) {
Ti.API.debug(e.error);
var toast = Titanium.UI.createNotification({
message : 'Error! Can not book table! ',
duration : Titanium.UI.NOTIFICATION_DURATION_SHORT
});
toast.show();
Ti.API.info("Status code :" + xhr.status);
};
xhr.onload = function() {
if (xhr.status == 200) {
Ti.API.info("XHR Status : " + xhr.status);
oID = JSON.parse(this.responseText);
Ti.API.info("Response from server :" + oID);
var id = oID;
tempData = {
oId : id,
itemName : name,
qtyPerPlate : qty,
qtyPerKg : '0',
pricePerPlate : price,
pricePerKg : '0',
type : type
};
arrayOBJ.push(tempData);
orderData = {
Item : arrayOBJ
};
JSONStringData = JSON.stringify(orderData);
Ti.API.info("Data Added :" + orderData);
var toast = Titanium.UI.createNotification({
message : 'Added Data!',
duration : Titanium.UI.NOTIFICATION_DURATION_SHORT
});
toast.show();
} else {
Ti.API.info("XHR Status : " + xhr.status);
}
};
Ti.API.info("id :" + id);
Ti.API.info("name :" + logName);
});
I got it working. Here's what i changed.
xhrpost.setRequestHeader('User-Agent', 'My User Agent');
xhrpost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
There is no need to set charset and enctype so remove it and then try to call.