Skip to content

Instantly share code, notes, and snippets.

@kopiro
Last active February 18, 2016 15:33
Show Gist options
  • Save kopiro/d78b236bc4c3004db4fe to your computer and use it in GitHub Desktop.
Save kopiro/d78b236bc4c3004db4fe to your computer and use it in GitHub Desktop.
PHP Oauth Client parser
<?php
Route::get('oauth/client', function() {
$url = OAUTH_DOMAIN . '/oauth/access_token';
$post = [
'grant_type' => 'authorization_code',
'code' => Input::get('code'),
'redirect_uri' => OAUTH_REDIRECT_URI,
'client_id' => OAUTH_ID,
'client_secret' => OAUTH_SECRET
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($post));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment