Skip to content

Instantly share code, notes, and snippets.

@schorsch
Last active September 25, 2015 01:47
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 schorsch/843226 to your computer and use it in GitHub Desktop.
Save schorsch/843226 to your computer and use it in GitHub Desktop.
Minimal example of how to authenticate a SalesKing app
<?php
$app_id = "APP_CLIENT_ID";
$app_secret = "APP_SECRET";
$app_url = "http://localhost/oauth_test";
$app_scope = "api/clients:read";
$sk_url = "https://SUBDOMAIN.salesking.eu";
$code = $_REQUEST["code"];
if(empty($code)) { # redirect to authorize url
$dialog_url = $sk_url . "/oauth/authorize?" .
"client_id=". $app_id .
"&scope=" . urlencode($app_scope);
"&redirect_uri=" . urlencode($app_url);
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
# build url to get the access token
$token_url = $sk_url . "/oauth/token?" .
"client_id=". $app_id .
"&redirect_uri=" . urlencode($app_url) .
"&client_secret=" . $app_secret .
"&code=" . $code;
# GET and parse resonse json
$resp = json_decode(file_get_contents($token_url));
# build url
$usr_url = $sk_url . "/api/users/current?access_token=" . $resp->access_token;
# GET info about current user
$user = json_decode(file_get_contents($usr_url));
echo("King: " . $user->user->email);
?>
@althaus
Copy link

althaus commented Jun 26, 2013

Token URL has changed. It has to be /oauth/token? in line 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment