-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClient.php
53 lines (35 loc) · 1.51 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
49
50
51
52
53
<?php
namespace IdnoPlugins\Pnut {
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($endpointUrl, $grant_type = 'authorization_code', array $parameters)
{
if ($parameters['state'] != \Idno\Core\site()->plugins()->get('Pnut')->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\Pnut\Main::$TOKEN_ENDPOINT, $parameters);
}
public function setAccessToken($token)
{
$this->access_token = $token;
}
}
}