Created
April 3, 2021 00:36
-
-
Save igoravl/41f75084ab0207c56b522b0a6cdf253c to your computer and use it in GitHub Desktop.
Post authenticated message to Azure DevOps Incoming Webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param | |
( | |
# URL to the Azure DevOps incoming webhook endpoint. Expected format is | |
# https://dev.azure.com/<org>/_apis/public/distributedtask/webhooks/<svc-trig>/?api-version=6.0-preview. | |
[uri] | |
$Url, | |
# Shared secret used to sign the JSON payload. Must be the same value supplied during | |
# the creation of the Incoming Webhook service connection | |
[string] | |
$Secret, | |
# HTTP header name to send the hash signature. When omitted, defaults to "X-Hub-Signature" | |
[string] | |
$HeaderName = 'X-Hub-Signature', | |
# JSON payload to send to the Azure DevOps web hook | |
[string] | |
$Body | |
) | |
$hmacSha = New-Object System.Security.Cryptography.HMACSHA1 -Property @{ | |
Key = [Text.Encoding]::ASCII.GetBytes($secret) | |
} | |
$hashBytes = $hmacSha.ComputeHash([Text.Encoding]::UTF8.GetBytes($body)) | |
$signature = '' | |
$hashBytes | ForEach-Object { $signature += $_.ToString('x2')} | |
$headers = @{ | |
$headerName = "sha1=$signature" | |
} | |
Invoke-WebRequest -Uri $Url -Body $Body -Method Post -ContentType 'application/json' -Headers $headers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment