Skip to content

Instantly share code, notes, and snippets.

@LazyDay
Created October 25, 2017 17:06
Show Gist options
  • Save LazyDay/67131ff0feb6b36fa74a14f4bcea3553 to your computer and use it in GitHub Desktop.
Save LazyDay/67131ff0feb6b36fa74a14f4bcea3553 to your computer and use it in GitHub Desktop.
public function actionLink()
{
$url = 'https://accounts.google.com/o/oauth2/auth';
$redirect_uri = 'http://hh.dev/index.php?r=things/token';
$client_id = '';
$params = array(
'redirect_uri' => $redirect_uri,
'response_type' => 'code',
'client_id' => $client_id,
'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/cloudprint'
);
echo $link = '<p><a href="' . $url . '?' . urldecode(http_build_query($params)) . '">Аутентификация через Google</a></p>';
}
public function actionToken($code){
$redirect_uri = 'http://hh.dev/index.php?r=things/token';
$client_id = '';
$client_secret = '';
$params = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'redirect_uri' => $redirect_uri,
'grant_type' => 'authorization_code',
'code' => $code
);
$url = 'https://accounts.google.com/o/oauth2/token';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, urldecode(http_build_query($params)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
$tokenInfo = json_decode($result, true);
print_r($tokenInfo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment