-
Notifications
You must be signed in to change notification settings - Fork 0
/
Github.php
34 lines (29 loc) · 1021 Bytes
/
Github.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
* @author gaobinzhan <gaobinzhan@gmail.com>
*/
class Github
{
public function index()
{
$config = new \OAuth\Github\Config();
$config->setClientId('clientid');
$config->setRedirectUri('redirect_uri');
$config->setState('easyswoole');
$oauth = new \OAuth\Github\OAuth($config);
$this->response()->redirect($oauth->getAuthUrl());
}
public function callback()
{
$params = $this->request()->getQueryParams();
$config = new \OAuth\Github\Config();
$config->setClientId('clientid');
$config->setClientSecret('secret');
$config->setRedirectUri('redirect_uri');
$oauth = new \OAuth\Github\OAuth($config);
$accessToken = $oauth->getAccessToken('easyswoole', $params['state'], $params['code']);
$userInfo = $oauth->getUserInfo($accessToken);
var_dump($userInfo);
if (!$oauth->validateAccessToken($accessToken)) echo 'access_token 验证失败!' . PHP_EOL;
}
}