Skip to content

Instantly share code, notes, and snippets.

@tristansokol
Created November 22, 2017 18:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristansokol/6572bf9aa0907505cfd453a76223a062 to your computer and use it in GitHub Desktop.
Save tristansokol/6572bf9aa0907505cfd453a76223a062 to your computer and use it in GitHub Desktop.
callback for php oauth example
<?php
$client_id = '';
$client_secret = '';
$redirect_uri= "http://localhost:8080/callback.php";
$authorization_code = $_GET['code'];
if(!$authorization_code){
die('something went wrong!');
}
$url = 'https://connect.squareup.com/oauth2/token';
$data = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'redirect_uri' => $redirect_uri,
'code' => $authorization_code
);
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment