Company/Classroom/Enterprise 設定 - Webhooks
僅為 提供
管理員可以使用 webhooks 來檢查資料存取的完整性,確認通知是真正由 Onshape 所送出,且未在傳輸過程中遭到竄改。啟用 webhook 基本驗證會將授權標頭填入所有 webhook 要求中。
若要巡覽您 Onshape 中的「Webhooks」設定,請按一下 Onshape 視窗右上角的帳戶使用者圖示 ()。這樣會開啟一個下拉功能表,然後按一下 [Company/Classroom/Enterprise 設定]。
按一下頁面左側清單中的 [Webhooks]:
Company 設定 > Webhooks
Enterprise 設定 > Webhooks
![封閉](../../Skins/Default/Stylesheets/Images/transparent.gif)
管理員可以使用 webhooks 來檢查資料存取的完整性,確認通知是真正由 Onshape 所送出,且未在傳輸過程中遭到竄改。啟用 webhook 基本驗證會將授權標頭填入所有 webhook 要求中。Webhook 簽章會設定 webhooks 使用簽章來保護免於攻擊。產生 主要與次要金鑰來在您生產應用程式中輪流使用。這樣可讓管理員取代或交換金鑰而不會中斷目前的連線。如果與金鑰之一相符,Onshape 會接受其是有效的。複製到剪貼簿可將相關的金鑰送至剪貼簿中。重設 會從相關的欄位中移除金鑰。在產生主要金鑰之後,按一下 儲存變更 來接受輸入。
管理員應確認所有 webhooks 端點位置 (https) 都是安全的,因為這個資料不是加密的。
會使用下列的結構來將簽章值與 webhook 目標比對:
Signature = <Base64<HMAC256-digest<<timestamp header value>.<webhook payload>>>
Onshape webhooks 包含下列額外的標頭:
-
X-onshape-webhook-timestamp - 當傳送 webhook 時表示的時間壓印
-
X-onshape-webhook-signature-primary - 如果在 Company 設定中有指定主要的簽章金鑰則會出現
-
X-onshape-webhook-signature-secondary - 如果在 Company 設定中有指定次要的簽章金鑰則會出現
![封閉](../../Skins/Default/Stylesheets/Images/transparent.gif)
JAVA
void matchSignatureHeader(String messageBody, String timestamp, String signatureKey, String signature) throws Exception {
String payload = timestamp + "." + messageBody;
String algorithm = "HmacSHA256";
Mac mac = Mac.getInstance(algorithm);
mac.init(new SecretKeySpec(signatureKey.getBytes(), algorithm));
byte[] payloadBytes = mac.doFinal(payload.getBytes());
Assert.assertArrayEquals(payloadBytes, Base64.decodeBase64(signature.getBytes()));
}
NODE.JS
const crypto = require('crypto');
……
var signatureKey; // The primary or secondary key
var message = timestampHeader + "." + rawPayload; // The timestamp header and the webhook payload
var hashValue = crypto.createHmac('SHA256', signatureKey).update(message).digest('base64');
if (hashValue === signatureHeader) { // signatureHeader is the primary or secondary signature header received with the webhook
// Signatures match
}