-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClient.php
48 lines (31 loc) · 1.18 KB
/
Client.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace IdnoPlugins\Bitly {
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}";
foreach ($parameters as $key => $value)
$url .= '&' . urlencode($key) . '=' . urlencode($value);
return $url;
}
public function getAccessToken($grant_type = 'authorization_code', array $parameters) {
if ($parameters['state'] != \Idno\Core\site()->plugins()->get('Bitly')->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\Bitly\Main::$TOKEN_ENDPOINT, $parameters);
}
public function setAccessToken($token) {
$this->access_token = $token;
}
}
}