Skip to content

Instantly share code, notes, and snippets.

@seven1m
Last active June 19, 2023 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seven1m/f81d636e1b917fb07d6cb53235ffca94 to your computer and use it in GitHub Desktop.
Save seven1m/f81d636e1b917fb07d6cb53235ffca94 to your computer and use it in GitHub Desktop.
Example HMAC-SHA256 calculation for Planning Center Webhook Payload
require 'openssl'
# get this secret from the Webhooks UI https://api.planningcenteronline.com/webhooks
secret = '2608ab74db02d670279278a90585fca300953f0a19fd96529cb61bb92ed39d86'
# raw unformatted payload
data = '{"data":[{"id":"cac783dc-75e7-4c5b-88e8-502d9d8682ae","type":"EventDelivery","attributes":{"name":"people.v2.events.person.updated","attempt":1,"payload":"{\"data\":{\"type\":\"Person\",\"id\":\"125587227\",\"attributes\":{\"accounting_administrator\":false,\"anniversary\":null,\"avatar\":\"https://avatars.planningcenteronline.com/uploads/initials/K.png\",\"birthdate\":null,\"can_create_forms\":false,\"can_email_lists\":false,\"child\":false,\"created_at\":\"2023-04-28T19:05:52Z\",\"demographic_avatar_url\":\"https://avatars.planningcenteronline.com/uploads/initials/K.png\",\"directory_status\":\"no_access\",\"first_name\":\"Kid\",\"gender\":null,\"given_name\":null,\"grade\":null,\"graduation_year\":null,\"inactivated_at\":null,\"last_name\":\"222\",\"medical_notes\":null,\"membership\":null,\"middle_name\":null,\"name\":\"Kid 222\",\"nickname\":null,\"passed_background_check\":false,\"people_permissions\":null,\"remote_id\":null,\"school_type\":null,\"site_administrator\":false,\"status\":\"active\",\"updated_at\":\"2023-06-19T14:50:30Z\"},\"relationships\":{\"primary_campus\":{\"data\":null},\"gender\":{\"data\":null}},\"links\":{\"\":\"https://api.planningcenteronline.com/people/v2/people/125587227/\",\"addresses\":\"https://api.planningcenteronline.com/people/v2/people/125587227/addresses\",\"apps\":\"https://api.planningcenteronline.com/people/v2/people/125587227/apps\",\"connected_people\":\"https://api.planningcenteronline.com/people/v2/people/125587227/connected_people\",\"emails\":\"https://api.planningcenteronline.com/people/v2/people/125587227/emails\",\"field_data\":\"https://api.planningcenteronline.com/people/v2/people/125587227/field_data\",\"household_memberships\":\"https://api.planningcenteronline.com/people/v2/people/125587227/household_memberships\",\"households\":\"https://api.planningcenteronline.com/people/v2/people/125587227/households\",\"inactive_reason\":null,\"marital_status\":null,\"message_groups\":\"https://api.planningcenteronline.com/people/v2/people/125587227/message_groups\",\"messages\":\"https://api.planningcenteronline.com/people/v2/people/125587227/messages\",\"name_prefix\":null,\"name_suffix\":null,\"notes\":\"https://api.planningcenteronline.com/people/v2/people/125587227/notes\",\"organization\":\"https://api.planningcenteronline.com/people/v2/people/125587227/organization\",\"person_apps\":\"https://api.planningcenteronline.com/people/v2/people/125587227/person_apps\",\"phone_numbers\":\"https://api.planningcenteronline.com/people/v2/people/125587227/phone_numbers\",\"platform_notifications\":\"https://api.planningcenteronline.com/people/v2/people/125587227/platform_notifications\",\"primary_campus\":null,\"school\":null,\"social_profiles\":\"https://api.planningcenteronline.com/people/v2/people/125587227/social_profiles\",\"workflow_cards\":\"https://api.planningcenteronline.com/people/v2/people/125587227/workflow_cards\",\"workflow_shares\":\"https://api.planningcenteronline.com/people/v2/people/125587227/workflow_shares\",\"self\":\"https://api.planningcenteronline.com/people/v2/people/125587227\",\"html\":\"https://people.planningcenteronline.com/people/AC125587227\"}},\"included\":[],\"meta\":{\"can_include\":[\"addresses\",\"emails\",\"field_data\",\"households\",\"inactive_reason\",\"marital_status\",\"name_prefix\",\"name_suffix\",\"organization\",\"person_apps\",\"phone_numbers\",\"platform_notifications\",\"primary_campus\",\"school\",\"social_profiles\"],\"parent\":{\"id\":\"127\",\"type\":\"Organization\"},\"public\":{\"attributes\":{\"merged\":null}}}}"},"relationships":{"organization":{"data":{"type":"Organization","id":"127"}}}}]}'
digest = OpenSSL::Digest.new('SHA256')
mac = OpenSSL::HMAC.hexdigest(digest, secret, data)
p mac # => "a0782fde663e7ee25a99b9d44f45434120ff027ba98ef333a83a4590fcc97828"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment