Page MenuHomePhabricator

Improve Python HMAC example in webhook documentation
AbandonedPublic

Authored by fwilson42 on Jun 26 2018, 2:33 AM.
Tags
None
Referenced Files
F18754987: D19508.id.diff
Sun, Oct 5, 2:52 AM
F18749807: D19508.diff
Sat, Oct 4, 5:12 AM
F18742001: D19508.id46646.diff
Thu, Oct 2, 4:51 PM
F18646450: D19508.id46646.diff
Fri, Sep 19, 10:03 AM
F18604291: D19508.id.diff
Sat, Sep 13, 6:25 PM
F18463952: D19508.id.diff
Sep 2 2025, 2:50 AM
F18454683: D19508.diff
Sep 1 2025, 5:33 AM
F18409066: D19508.diff
Aug 30 2025, 3:36 AM
Subscribers
Tokens
"Hungry Hippo" token, awarded by yelirekim.

Details

Summary

This changes the example from a "subprocess" call out to PHP to use
Python's standard library "hmac" instead. This removes the dependency
on PHP; webhooks might not be run on a machine with it installed.

Test Plan

Run the PHP example with key = "test key" and body = "test body":

echo hash_hmac('sha256', 'test body', 'test key');
// => e327344d7533dfd50ceed6541c3ba412b06cc52b0cdfc900fcaf58992b470617

Run the Python example with the same parameters (Python 2):

>>> import hashlib
>>> import hmac
>>> hmac.new('test key', 'test body', hashlib.sha256).hexdigest()
'e327344d7533dfd50ceed6541c3ba412b06cc52b0cdfc900fcaf58992b470617'

And Python 3:

>>> import hashlib
>>> import hmac
>>> hmac.new(b'test key', b'test body', hashlib.sha256).hexdigest()
'e327344d7533dfd50ceed6541c3ba412b06cc52b0cdfc900fcaf58992b470617'

Note that all values are the same.

Diff Detail

Repository
rP Phabricator
Branch
master
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 20453
Build 27780: arc lint + arc unit