Created
May 28, 2013 22:10
-
-
Save tstachl/5666559 to your computer and use it in GitHub Desktop.
desk.com OAuth with php.
This file contains hidden or 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
<?php | |
$subdomain = 'your-sitename'; | |
$req_url = 'https://'.$subdomain.'.desk.com/oauth/request_token'; | |
$authurl = 'https://'.$subdomain.'.desk.com/oauth/authorize'; | |
$acc_url = 'https://'.$subdomain.'.desk.com/oauth/access_token'; | |
$api_url = 'https://'.$subdomain.'.desk.com/api/v2'; | |
// SET YOUR CALLBACK URL | |
$callback = 'http://localhost:3000/auth/desk/callback'; | |
$conskey = 'YOUR_CONSUMER_KEY'; | |
$conssec = 'YOUR_CONSUMER_SECRET'; | |
session_start(); | |
try { | |
$oauth = new OAuth($conskey, $conssec, OAUTH_SIG_METHOD_HMACSHA1); | |
$oauth->enableDebug(); | |
$request_token_info = $oauth->getRequestToken($req_url, $callback); | |
if(!isset($_GET['oauth_token']) && !$_SESSION['state']) { | |
$request_token_info = $oauth->getRequestToken($req_url, $api_ret); | |
$_SESSION['secret'] = $request_token_info['oauth_token_secret']; | |
$_SESSION['state'] = 1; | |
header('Location: '.$authurl.'?oauth_token='.$request_token_info['oauth_token']); | |
exit; | |
} else if($_SESSION['state']==1) { | |
$oauth->setToken($_GET['oauth_token'], $_SESSION['secret']); | |
$access_token_info = $oauth->getAccessToken($acc_url); | |
$_SESSION['state'] = 2; | |
$_SESSION['token'] = $access_token_info['oauth_token']; | |
$_SESSION['secret'] = $access_token_info['oauth_token_secret']; | |
} | |
$oauth->setToken($_SESSION['token'], $_SESSION['secret']); | |
$oauth->fetch("$api_url/cases.json"); | |
$json = json_decode($oauth->getLastResponse()); | |
print_r($json); | |
} catch(OAuthException $E) { | |
print_r($E); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked perfect. Thanks