PHP example for generating challenge response for Twitter webhooks
| <?php | |
| // Example app consumer secret found in apps.twitter.com | |
| const APP_CONSUMER_SECRET = 'z3ZX4v7mAAUGykl3EcmkqbartmuW8VFOOzCloLx9Q45P0hLrFu'; | |
| // Example token provided by incoming GET request | |
| $token = $_GET['crc_token']; | |
| /** | |
| * Creates a HMAC SHA-256 hash created from the app TOKEN and | |
| * your app Consumer Secret. | |
| * @param token the token provided by the incoming GET request | |
| * @return string | |
| */ | |
| function get_challenge_response($token) { | |
| $hash = hash_hmac('sha256', $token, APP_CONSUMER_SECRET, true); | |
| $response = array( | |
| 'response_token' => 'sha256=' . base64_encode($hash) | |
| ); | |
| return json_encode($response); | |
| } | |
| // prints result | |
| echo get_challenge_response($token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment