2016-10-19 14 views
1

MSDNのドキュメント、記事、およびスタックのオーバーフローを見てきましたが、問題の内容がわかりません。Azureストレージ認証(JavaScript)

https://www.kaizenspark.com/blog/topic/mirthconnect

私はマースConnectを使用してAzureのキューストレージに接続しようとするために、この記事を使用してきました。

Azureの認可がように行われる:

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); 

私は入力自分のアカウント名、キー、およびパス以外は何も変わっていないしました。 ここの文書によると:https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx#、stringToSignは正しいようです。

はしかし、私はこのエラーを取得する:

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> 

は、私はちょうど、プライバシーのための「キー」と、アカウント名、およびキュー名に要求IDを変更したが、それは私に表示されていたとして、それ以外の場合はエラーメッセージです。どんな支援も大歓迎です!

+0

あなたが何をしようとする動作を伝えることはできますか?キューにメッセージを追加しようとしているようですが、確認したかったようです。また、クラウドストレージアカウントではなく、ストレージエミュレータでこれを実行しようとしていることを確認してください。 –

答えて

0

あなたのエラーメッセージよると:

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'

をあなたのSDKは、署名を生成する時に間違った何かを得るようです。 CanonicalizedResource/<accountname>/<queuename>/messagesのようになりますが、今はあなたの署名に/messagesがありません。

Put Messageため、次の純粋なNode.jsのコードを参照してください:

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) 
    } 
});