I've been looking at MSDN docs, articles, and stack overflow and I'm not sure what the problem is.
https://www.kaizenspark.com/blog/topic/mirthconnect
I've been using this article to try to connect to Azure queue storage using Mirth Connect.
Azure authorization is done as such:
importPackage(javax.crypto);
importPackage(javax.crypto.spec);
importPackage(org.apache.commons.codec.binary);
// Change the variables below to your actual account details
// Remember the queue name must be lower case or it will fail
var account = "devstoreaccount1";
var key = "Access key";
var path = "devstoreaccount1/myqueuename/messages";
// No changes below this line
var apiVersion = "2011-08-18";
var contentLength = String(tmp).length;
var gmtDateString = new Date().toGMTString();
var stringToSign =
"POST\n" + /*HTTP Verb*/
"\n" + /*Content-Encoding*/
"\n" + /*Content-Language*/
contentLength + "\n" + /*Content-Length*/
"\n" + /*Content-MD5*/
"text/xml; charset=UTF-8\n" + /*Content-Type*/
"\n" + /*Date*/
"\n" + /*If-Modified-Since */
"\n" + /*If-Match*/
"\n" + /*If-None-Match*/
"\n" + /*If-Unmodified-Since*/
"\n" + /*Range*/
/* CanonicalizedHeaders */
"x-ms-date:" + gmtDateString + "\n" +
"x-ms-version:" + apiVersion + "\n" +
/* CanonicalizedResource */
"/" + account + "/" + path;
var mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(Base64.decodeBase64(key), mac.getAlgorithm()));
mac.update(java.lang.String(stringToSign).getBytes("UTF-8"));
var hmac = Base64.encodeBase64String(mac.doFinal());
connectorMap.put('Authorization', 'SharedKey ' + account + ':' + hmac);
connectorMap.put('x-ms-date', gmtDateString);
connectorMap.put('x-ms-version', apiVersion);
connectorMap.put('path', path);
I've changed nothing other than input my own account name, key, and path.
According to docs here: https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx# , the stringToSign seems correct.
However, I get this error:
ERROR MESSAGE: <?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:'id' Time:2016-10-19T17:24:51.6491513Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'key' is not the same as any computed signature. Server used following string to sign: 'POST 88 text/xml; charset=UTF-8 x-ms-date:Wed, 19 Oct 2016 17:24:50 GMT x-ms-version:2011-08-18 /accountname/queuename'.</AuthenticationErrorDetail></Error>
I changed the request id to 'key' and account name, and queue name just for privacy but otherwise the error message is as it was displayed to me. Any assistance would be much appreciated!
According your error message:
Server used following string to sign: 'POST 88 text/xml; charset=UTF-8 x-ms-date:Wed, 19 Oct 2016 17:24:50 GMT x-ms-version:2011-08-18 /accountname/queuename'
It seems your SDK get something wrong during generating the signature. The CanonicalizedResource should be like /<accountname>/<queuename>/messages, which now is lacking /messages in your signature.
Please refer the following pure node.js code for Put Message:
var crypto = require('crypto');
var request = require('request');
var key = "<key>";
var strTime = (new Date()).toGMTString();
var apiVersion = "2011-08-18";
var account = "<accountname>";
var path = "myqueue/messages";
var body = "<QueueMessage>"+
"<MessageText>PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg==</MessageText>"+
"</QueueMessage>";
var strToSign =
"POST\n" + /*HTTP Verb*/
"\n" + /*Content-Encoding*/
"\n" + /*Content-Language*/
body.length + "\n" + /*Content-Length*/
"\n" + /*Content-MD5*/
"\n" + /*Content-Type*/
"\n" + /*Date*/
"\n" + /*If-Modified-Since */
"\n" + /*If-Match*/
"\n" + /*If-None-Match*/
"\n" + /*If-Unmodified-Since*/
"\n" + /*Range*/
/* CanonicalizedHeaders */
"x-ms-date:" + strTime + "\n" +
"x-ms-version:" + apiVersion + "\n" +
/* CanonicalizedResource */
"/" + account + "/" + path;
var sharedKey = crypto.createHmac('sha256',new Buffer(key,'base64')).update(strToSign, 'utf-8').digest('base64');
var auth = "SharedKey "+account+":"+sharedKey;
var options = {
method: 'POST',
url: 'https://'+account+'.queue.core.windows.net/'+path,
headers: {
'Authorization':auth,
'x-ms-date':strTime,
'x-ms-version':apiVersion
},
body: body
};
request(options, function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(info);
}else{
// console.log(response)
console.log(body)
}
});
Related
I stuck sending mails to email script for multiple receiver
May someone could help me
var recipient2=(ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T16").getValue()) + ',' + (ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T25").getValue()) + ',' + (ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T28").getValue()) ;
it should send to 3 different mails which could change.
Any help is welcome
This is my complete code, I try to work with cc and bcc but it always send the mail only to one email
// Define your variables here
function mailPDFtoHO( optSSId, optSheetId ) {
//If a sheet ID was provided, open that sheet, otherwise assume script is
//sheet-bound, and open the active spreadsheet.
var ss = (optSSId) ? SpreadsheetApp.openById(optSSId) : SpreadsheetApp.getActiveSpreadsheet();
//Get URL of spreadsheet, and remove the trailing 'edit'
var url = ss.getUrl().replace(/edit$/,'');
//Get folder containing spreadsheet, for later export
var parents = DriveApp.getFileById(ss.getId()).getParents();
if (parents.hasNext()) {
var folder = parents.next();
}
else {
folder = DriveApp.getRootFolder();
}
//Get array of all sheets in spreadsheet
// var sheets = ss.getSheets();
//Loop through all sheets, generating PDF files.
//for (var i=0; i<sheets.length; i++) {
//var sheet = sheets[i];
//If provided a optSheetId, only save it.
//if (optSheetId && optSheetId !== sheet.getSheetId()) continue;
//additional parameters for exporting the sheet as a pdf
var url_ext = 'export?exportFormat=pdf&format=pdf' //export as pdf
//+ '&gid=' + sheet.getSheetId() //the sheet's Id
//following parameters are optional...
+ '&size=A4' //paper size
+ '&portrait=false' //orientation, false for landscape
+ '&fitw=true' //fit to width, false for actual size
+ '&sheetnames=false&printtitle=false&pagenumbers=false' //hide optional headers and footers
+ '&gridlines=false' //hide gridlines
+ '&fzr=false' //do not repeat row headers (frozen rows) on each page
+ '&gid=1672240374'
+ '&ir=false' //seems to be always false
+ '&ic=false' //same as ic
+ '&r1=1' //Start Row number - 1, so row 1 would be 0 , row 15 wold be 14
+ '&c1=0' //Start Column number - 1, so column 1 would be 0, column 8 would be 7
+ '&r2=78' //End Row number
+ '&c2=29'; //End Column number;
var options = {
headers: {
'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
}
}
var response = UrlFetchApp.fetch(url + url_ext, options);
var blob = response.getBlob().setName(ss.getName() + '_' + ss.getSheetByName("Timesheet").getRange("B5").getValue() + "_" + ss.getSheetByName("Timesheet").getRange("X5").getValue() + "_" + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T7").getValue() + "." + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T5").getValue() + '.pdf');
//from here you should be able to use and manipulate the blob to send and email or create a file per usual.
//In this example, I save the pdf to drive
var recipient1=Session.getActiveUser().getEmail();
var recipient2=ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T16").getValue() ;
var recipient3=ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T25").getValue() ;
var recipient4=ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T28").getValue() ;
var subject1=SpreadsheetApp.getActiveSpreadsheet().getName() + ' ' + ss.getSheetByName("Timesheet").getRange("B5").getValue() + ' ' + ss.getSheetByName("Timesheet").getRange("X5").getValue() + " " + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T7").getValue() + "/" + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T5").getValue() ;
var subject2='FW:' + ' ' + SpreadsheetApp.getActiveSpreadsheet().getName() + ' ' + ss.getSheetByName("Timesheet").getRange("B5").getValue() + ' ' + ss.getSheetByName("Timesheet").getRange("X5").getValue() + " " + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T7").getValue() + "/" + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T5").getValue() ;
var body="Hello " + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T13").getValue() + "," + "\n\nPlease find attached the timesheet for " + ss.getSheetByName("Timesheet").getRange("X5").getValue() + ".\n\nBest Regards,\n\n" + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T10").getValue();
var message1 = {
to: recipient1,
subject: subject1,
body: body,
attachments: [blob]
}
var message2 = {
to: recipient2,
cc: recipient3,
bcc: recipient4,
subject: subject2,
body: body,
attachments: [blob]
}
var confirm1 = Browser.msgBox('send confirmation','Are you sure you want to send this mail to your mail-box?', Browser.Buttons.OK_CANCEL);
if(confirm1=='ok'){ MailApp.sendEmail(message2)};
var confirm2 = Browser.msgBox('send confirmation','Are you sure you want to send this mail to your Bundget Resposible ' + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T19").getValue() + ' , time agent ' + ss.getSheetByName("ECA-Points & Personal Nr.").getRange("T22").getValue() + ' and DAOS?', Browser.Buttons.OK_CANCEL);
if(confirm2=='ok'){ MailApp.sendEmail(message1)};
I am working on twitter integration. I am using CryptoJs to create a signature. Here is the code.
The issue is, following code is working without "in_reply_to_status_id" parameter, but with that parameter it is giving "could not authenticate issue".
var autSign =
'oauth_consumer_key=' + percentEncode(consumer_key) + '&' +
'oauth_nonce=' + percentEncode(nonce) + '&' +
'oauth_signature_method=HMAC-SHA1&' +
'oauth_timestamp=' + timeStamp + '&' +
'oauth_token=' + percentEncode(access_token) + '&' +
'oauth_version=1.0&status=test3&in_reply_to_status_id=1217119832744898564';
var baseString =
"POST&" +
percentEncode(endpoint) + "&" + percentEncode(autSign);
var signingKey = this.percentEncode(consumer_secret) +
"&" + this.percentEncode(access_token_secret);
var encrypted = CryptoJS.HmacSHA1(baseString, signingKey);
var signature = CryptoJS.enc.Base64.stringify(encrypted);
I need to send a http request to firebase that has this shape
https://db.firebaseio.com/0.json?&orderBy="name"&startAt=query&endAt=query+"\uf8ff"&limitToLast=1&print=pretty&auth=auth_token
My problem is that when I call this request I've a 400 error in console because it replace %22 to question marks and other symbols for \uf8ff and I think firebase doesn't recognize that.
let name = '"name"';
let cod = '"\uf8ff"';
let url = ('https://db.firebaseio.com/0.json?&orderBy=' + encodeURIComponent(name) + '&startAt=' + encodeURIComponent(birraName) + '&endAt=' + encodeURIComponent(birraName) + '+' + encodeURIComponent(cod) + '&limitToLast=1&print=pretty&auth=' + encodeURIComponent(this.idToken));
let response = this.http.get(url).map(res => res.json());
return response;
And then in console
400 Bad Request
Do you have any thougths?
You're missing quotes in your target string to mark string values. If you're searching for nodes starting with Marco, it should be https://db.firebaseio.com/0.json?&orderBy="name"&startAt="Marco"&endAt="Marco\uf8ff"&limitToLast=1&print=pretty&auth=auth_token. Note the double quotes around "Marco" and "Marco\uf8ff".
To build these in your JavaScript:
var url = 'https://db.firebaseio.com/0.json';
url = url + '?orderBy="' + encodeURIComponent(name) + '"';
url = url + "&startAt="' + encodeURIComponent(birraName) + '"';
url = url + "&endAt="' + encodeURIComponent(birraName) + '\uf8ff"';
url = url + '&limitToLast=1&print=pretty';
url = url + '&auth="' + encodeURIComponent(this.idToken))+'"";
Template literals might also be useful to keep this readable:
let url = (`https://db.firebaseio.com/0.json?orderBy=${encodeURIComponent(name)}&startAt=${encodeURIComponent(birraName)}&endAt=${encodeURIComponent(birraName)}${encodeURIComponent(cod)}&limitToLast=1&print=pretty&auth=${encodeURIComponent(this.idToken))}`;
I am trying to construct an Account level Shared Access Signiture so my client can access all containers in a storage account. I am following these docs Account SAS. It seems straight forward enough but I keep getting the following error message:
"Signature did not match. String to sign used was accountname\nrl\nb\nsc\n\n2016-10-09\n\n\n2015-04-05\n".
My parameters are identical so I suspect it has something to do with how I am hashing the String to Sign. Below is how I construct the token.
var crypto = require('crypto');
var accountName = 'accountname';
var accountKey = 'tH37FTlG3TUT86caMrt2y5kOzof8nFqqA6spzg6r7HPRojE1zDiLJD/xE4oLFDh4RNqAmymvlV7fm8W4SF8cJg==';
var signedPermissions = "sp=rl";
var signedServcies = "ss=b";
var signedResourceType = "srt=sc";
var signedExpiry = "se=2016-10-09";
var signedVersion = "sv=2015-04-05";
var stringToSign = accountName + "\n" + signedPermissions + "\n" + signedServcies + "\n" + signedResourceType + "\n" + signedExpiry + "\n" + signedVersion + "\n";
var hmacsha256 = crypto.createHmac('sha256', accountKey).update(stringToSign).digest('base64');
var token = signedPermissions + "&" + signedServcies + "&" + signedResourceType + "&" + signedExpiry + "&" + signedVersion + "&sig=" + hmacsha256;
I have tried using crypto-js as well but to no avail. The final URL used to access a blob in a container is...
"https://accountname.blob.core.windows.net/containername/blobName?srt=sc&se=2016-10-09&api-version=2015-04-05&sp=rl&ss=b&sv=2015-04-05&sig=IFD2wyfRAsHGU5IFg3RbwSJW6tRE0m0%2FxgAYvJ%2FmnEk%3D"
I have been trying for days and really would appreciate knowing what I'm doing wrong. Thanks.
Benzene, for stringToSign, the value should NOT has the parameter name?
var signedPermissions = "rl";
var signedServcies = "b";
var signedResourceType = "sc";
var signedExpiry = "2016-10-09";
var signedVersion = "2015-04-05";
Please try the following (code shamelessly taken from Azure Storage Node.js library):
var hmacsha256 = crypto.createHmac('sha256', new Buffer(accountKey, 'base64')).update(stringToSign, 'utf-8').digest('base64');
here am trying to get reccurring events from calendar list for sharepoint Online app and there am using code as like
hostWebUrl = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
function GetListData() {
var webUrl = hostWebUrl;// = "http://server/sitewhereyourlistexists";
var listGuid = "{2000da75-8663-42d9-9999-ad855c54b4e0}"
// An XMLHttpRequest object is used to access the web service
var xhr = new XMLHttpRequest();
var url = webUrl + "/_vti_bin/Lists.asmx";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
// The message body consists of an XML document
// with SOAP elements corresponding to the GetListItems method parameters
// i.e. listName, query, and queryOptions
var data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" +
"<listName>" + listGuid + "</listName>" +
"<query>" +
"<Query><Where>" +
"<DateRangesOverlap>" +
"<FieldRef Name=\"EventDate\"/>" +
"<FieldRef Name=\"EndDate\"/>" +
"<FieldRef Name=\"RecurrenceID\"/>" +
"<Value Type=\"DateTime\"><Today/></Value>" +
"</DateRangesOverlap>" +
"</Where></Query>" +
"</query>" +
"<queryOptions>" +
"<QueryOptions>" +
"<ExpandRecurrence>TRUE</ExpandRecurrence>" +
"</QueryOptions>" +
"</queryOptions>" +
"</GetListItems>" +
"</soap:Body>" +
"</soap:Envelope>";
// Here we define what code we want to run upon successfully getting the results
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var doc = xhr.responseXML;
// grab all the "row" elements from the XML results
var rows = doc.getElementsByTagName("z:row");
var results = "Today's Schedule (" + rows.length + "):\n\n";
var events = {};
for (var i = 0, len = rows.length; i < len; i++) {
var id = rows[i].getAttribute("ows_FSObjType"); // prevent duplicates from appearing in results
if (!events[id]) {
events[id] = true;
var allDay = rows[i].getAttribute("ows_fAllDayEvent"),
title = rows[i].getAttribute("ows_Title"),
start = rows[i].getAttribute("ows_EventDate");
var index = start.indexOf(" ");
var date = start.substring(5, index) + "-" + start.substring(2, 4); // get the date in MM-dd-yyyy format
start = start.substring(index, index + 6); // get the start time in hh:mm format
var end = rows[i].getAttribute("ows_EndDate");
index = end.indexOf(" "); end = end.substring(index, index + 6); // get the end time in hh:mm format
results += date + " " + (allDay == "1" ? "All Day\t" : start + " to " + end) + " \t " + title + "\n";
}
}
alert(results);
} else {
alert("Error " + xhr.status);
}
}
};
// Finally, we actually kick off the query
xhr.send(data);
}
after calling this function in decument. ready section it is not retrieving any data but there is ine error which i can see in console of browser that is as below
You will click on the correct request in the left hand side panel, then select "Inspectors" in the right hand side top panel. Then choose between the different request and response options.