-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClient.php
More file actions
49 lines (31 loc) · 1.26 KB
/
Client.php
File metadata and controls
49 lines (31 loc) · 1.26 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace IdnoPlugins\Github {
class Client {
private $key;
private $secret;
public $access_token;
function __construct($apikey, $secret) {
$this->key = $apikey;
$this->secret = $secret;
}
public function getAuthenticationUrl($baseURL, $redirectURL, $parameters = []) {
$parameters['redirect_uri'] = $redirectURL;
$url = $baseURL . "?client_id={$this->key}&" . http_build_query($parameters);
//foreach ($parameters as $key => $value)
//$url .= '&' . urlencode($key) . '=' . urlencode($value);
return $url;
}
public function getAccessToken($endpointUrl, $grant_type = 'authorization_code', array $parameters) {
if ($parameters['state'] != \Idno\Core\site()->plugins()->get('Github')->getState())
throw new \Exception('State value not correct, possible CSRF attempt.');
unset($parameters['state']);
$parameters['client_id'] = $this->key;
$parameters['client_secret'] = $this->secret;
$parameters['grant_type'] = $grant_type;
return \Idno\Core\Webservice::post(\IdnoPlugins\Github\Main::$TOKEN_ENDPOINT, $parameters, ['Accept: application/json']);
}
public function setAccessToken($token) {
$this->access_token = $token;
}
}
}