| 10582 |
lgm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* OAuth2 Token
|
|
|
4 |
*
|
|
|
5 |
* @package OAuth2
|
|
|
6 |
* @category Token
|
|
|
7 |
* @author Phil Sturgeon
|
|
|
8 |
* @copyright (c) 2011 HappyNinjas Ltd
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
class OAuth2_Token_Access extends OAuth2_Token
|
|
|
12 |
{
|
|
|
13 |
/**
|
|
|
14 |
* @var string access_token
|
|
|
15 |
*/
|
|
|
16 |
protected $access_token;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @var int expires
|
|
|
20 |
*/
|
|
|
21 |
protected $expires;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* @var string refresh_token
|
|
|
25 |
*/
|
|
|
26 |
protected $refresh_token;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* @var string uid
|
|
|
30 |
*/
|
|
|
31 |
protected $uid;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Sets the token, expiry, etc values.
|
|
|
35 |
*
|
|
|
36 |
* @param array token options
|
|
|
37 |
* @return void
|
|
|
38 |
*/
|
|
|
39 |
public function __construct(array $options = null)
|
|
|
40 |
{
|
|
|
41 |
if ( ! isset($options['access_token']))
|
|
|
42 |
{
|
|
|
43 |
throw new Exception('Required option not passed: access_token'.PHP_EOL.print_r($options, true));
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// if ( ! isset($options['expires_in']) and ! isset($options['expires']))
|
|
|
47 |
// {
|
|
|
48 |
// throw new Exception('We do not know when this access_token will expire');
|
|
|
49 |
// }
|
|
|
50 |
|
|
|
51 |
$this->access_token = $options['access_token'];
|
|
|
52 |
|
|
|
53 |
// Some providers (not many) give the uid here, so lets take it
|
|
|
54 |
isset($options['uid']) and $this->uid = $options['uid'];
|
|
|
55 |
|
|
|
56 |
//Vkontakte uses user_id instead of uid
|
|
|
57 |
isset($options['user_id']) and $this->uid = $options['user_id'];
|
|
|
58 |
|
|
|
59 |
//Mailru uses x_mailru_vid instead of uid
|
|
|
60 |
isset($options['x_mailru_vid']) and $this->uid = $options['x_mailru_vid'];
|
|
|
61 |
|
|
|
62 |
// We need to know when the token expires, add num. seconds to current time
|
|
|
63 |
isset($options['expires_in']) and $this->expires = time() + ((int) $options['expires_in']);
|
|
|
64 |
|
|
|
65 |
// Facebook is just being a spec ignoring jerk
|
|
|
66 |
isset($options['expires']) and $this->expires = time() + ((int) $options['expires']);
|
|
|
67 |
|
|
|
68 |
// Grab a refresh token so we can update access tokens when they expires
|
|
|
69 |
isset($options['refresh_token']) and $this->refresh_token = $options['refresh_token'];
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Returns the token key.
|
|
|
74 |
*
|
|
|
75 |
* @return string
|
|
|
76 |
*/
|
|
|
77 |
public function __toString()
|
|
|
78 |
{
|
|
|
79 |
return (string) $this->access_token;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
} // End OAuth2_Token_Access
|