2017-03-22 91 views
0

我試圖使用http協議將消息發佈到DataPower的Azure服務總線。我應該如何憑據傳遞,因爲我得到一個未經授權的錯誤401DataPower - Azure服務總線集成

請幫助,因爲我來到這裏停留

感謝

+0

從[401個上的狀態代碼維基百科(https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors)「的響應必須包含一個包含適用於所請求資源的質詢的WWW-Authenticate標題字段「,該響應標題字段」WWW-Authenticate「包含什麼內容? –

回答

0

我想出瞭解決方案。以下是我如何實現SAS身份驗證令牌。

  1. 使用需要4個參數的Java模塊在IIB中生成SAS令牌: a。 b。Azure服務總線的資源URI b。密鑰 c。鍵名 d。以秒爲單位。
  2. 將SAS令牌設置在MQRFH2頭中併發送給DataPower
  3. 使用下面的xslt提取SAS令牌並設置爲DataPower中的HTTP POST請求的授權頭。

+0

沒有XSLT ...: – Anders

+0

我已將它添加到上一篇文章中,但它未在論壇中顯示。 abhi88

0

這取決於如果你正在使用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框架...

+0

我已經生成了SAS令牌,並且在將SAS令牌設置爲Authorization標頭值後,我將DataPower中的請求發佈到Azure服務總線。但我仍然收到401錯誤,說我沒有權利。無論如何看到Azure服務總線上收到的SAS令牌 – abhi88

+0

通過啓用服務中的DataPower Probe(MPGW?),如果您選擇最後一步並查看Headers選項卡,您可以看到已發送的標頭。這會告訴你發送給Azure的內容。 – Anders

0

由於這位官員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命令如下創建命名空間:

enter image description here

有關詳細信息,你可以參考這個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 

建設令牌

enter image description here

有關獲取一個SWT令牌更細節的SWT,你可以參考這個blog和這個tutorial關於如何從ACS請求令牌。