我試圖使用http協議將消息發佈到DataPower的Azure服務總線。我應該如何憑據傳遞,因爲我得到一個未經授權的錯誤401DataPower - Azure服務總線集成
請幫助,因爲我來到這裏停留
感謝
我試圖使用http協議將消息發佈到DataPower的Azure服務總線。我應該如何憑據傳遞,因爲我得到一個未經授權的錯誤401DataPower - Azure服務總線集成
請幫助,因爲我來到這裏停留
感謝
這取決於如果你正在使用Shared Access Signatures
(SAS)或Access Control Service
(ACS )爲您服務的巴士。
我推薦使用SAS!
不幸的是,Azure Node.js SDK有很多fs(文件系統)調用,DataPower GatewayScript無法處理,因此我們無法使用它。
這是一個片段,我發現的地方,我已經使用了SAS作爲GatewayScript創建標題:
'use strict';
var crypto = require('crypto');
// ServiceBus parameters
var namespace = '<Your-ServiceBus-Namespace>';
var queue ='<Your-Queue>';
var AccessKeyName = '<Your-AccessKey-Name>';
var AccessKey = '<Your-AccessKey>';
// Full ServiceBus Queue publisher URI
var ServiceBusUri = 'https://' + namespace + '.servicebus.windows.net' + '/' + queue;
function createSASToken(uri, keyName, key)
{
//Token expires in December
var expiry = '1417774602';
var crypto = require('crypto');
var signedString = encodeURIComponent(uri) + '\n' + expiry;
var hmac = crypto.createHmac('sha256', key);
hmac.update(signedString);
var signature = hmac.digest('base64');
var token = 'SharedAccessSignature sr=' + encodeURIComponent(uri) + '&sig=' + encodeURIComponent(signature) + '&se=' + expiry + '&skn=' + keyName;
return token;
}
var SASToken = createSASToken(ServiceBusUri, AccessKeyName, AccessKey)
console.log(SASToken);
var options = {
hostname: namespace + '.' + 'servicebus.Windows.net',
port: 443,
path: '/' + queue + '/messages',
method: 'POST',
headers: {
'Authorization': SASToken,
'Content-Type': 'application/atom+xml;type=entry;charset=utf-8',
}
};
// GatewayScript url-open() goes here...
// End
我剛剛從另一個項目,所以你需要拉出碼在其上添加一些處理程序和GatewayScript框架...
由於這位官員document提及服務總線認證和授權:
應用程序可以使用任一共享訪問簽名(SAS)認證,或通過天青Active Directory訪問控制(也稱爲訪問控制服務或ACS)天青服務總線進行認證。
SAS建議在ACS,因爲它提供服務總線簡單,靈活,易於使用的認證方案。應用程序可以在不需要管理授權「用戶」概念的情況下使用SAS。
1)共享訪問簽名
令牌是以下格式:
SharedAccessSignature sig=<signature-string>&se=<expiry>&skn=<keyName>&sr=<URL-encoded-resourceURI>
使用共享訪問簽名(在HTTP電平)sending message:
POST http{s}://<yournamespace>.servicebus.windows.net/<path>/messages
Authorization: SharedAccessSignature sr=https%3A%2F%2F<yournamespace>.servicebus.windows.net%2F<path>&sig=<your-signature>&se=1438205742&skn=KeyName
ContentType: application/atom+xml;type=entry;charset=utf-8
有關更多詳細信息,可參考此tutorial以基於您的開發語言生成SAS令牌。
2)訪問控制服務(ACS)
必須使用New-AzureSBNamespace PowerShell命令如下創建命名空間:
有關詳細信息,你可以參考這個blog 。
使用ACS發送消息:
POST http{s}://<yournamespace>.servicebus.windows.net/<path>/messages
Authorization: WRAP access_token={swt}
ContentType: application/atom+xml;type=entry;charset=utf-8
建設令牌
從[401個上的狀態代碼維基百科(https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors)「的響應必須包含一個包含適用於所請求資源的質詢的WWW-Authenticate標題字段「,該響應標題字段」WWW-Authenticate「包含什麼內容? –