Skip to content

Instantly share code, notes, and snippets.

@mehdimehdi
Last active January 2, 2016 16:09
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 mehdimehdi/8327935 to your computer and use it in GitHub Desktop.
Save mehdimehdi/8327935 to your computer and use it in GitHub Desktop.
Log a user in (create an account if user does not exists)
<?php
define ('PUNCHTAB_CLIENT_ID', '2128281015'); //client_id
define ('PUNCHTAB_SECRET_KEY', '< YOUR SECRET KEY >');
define ('PUNCHTAB_ACCESS_KEY', 'c370b56450e41a8f689fffb2374e7ef4'); //key
$user = array('id' => '2', 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@example.net', 'avatar_link' => 'http://s3.amazonaws.com/punchtab-static/zzzzzz/img/team/lewolf.jpg');
$auth_request = base64_encode(json_encode($user));
$timestamp=time();
$signature = hash_hmac('sha1', "$auth_request $timestamp", PUNCHTAB_SECRET_KEY);
$r = new HttpRequest('https://api.punchtab.com/v1/auth/sso', HttpRequest::METH_POST);
$payload = array('client_id' => PUNCHTAB_CLIENT_ID,
'key' => PUNCHTAB_ACCESS_KEY,
'auth_request' => $auth_request,
'timestamp' => $timestamp,
'signature' => $signature);
$r->addPostFields($payload);
echo $r->send()->getBody();
/* returns:
{
"status": "connected",
"authResponse": {
"expiresIn": 1209600,
"userID": "2_56730",
"newUser": false,
"uid": "4455181",
"accessToken": "6e2ee3d3ccc2db9f0599a56f4b30bdb1"
}
}
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment