-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccessToken.php
91 lines (77 loc) · 1.82 KB
/
AccessToken.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* SocialConnect project
* @author: Patsura Dmitry https://github.com/ovr <[email protected]>
*/
declare(strict_types=1);
namespace SocialConnect\OAuth1;
use SocialConnect\Provider\AccessTokenInterface;
use SocialConnect\Provider\Exception\InvalidAccessToken;
class AccessToken extends \SocialConnect\OAuth1\Token implements AccessTokenInterface
{
/**
* @var string|null
*/
protected $userId;
/**
* @var string
*/
protected $screenName;
public function __construct(array $token)
{
if (!isset($token['oauth_token'])) {
throw new InvalidAccessToken(
'API returned data without oauth_token field'
);
}
if (!isset($token['oauth_token_secret'])) {
throw new InvalidAccessToken(
'API returned data without oauth_token_secret field'
);
}
parent::__construct($token['oauth_token'], $token['oauth_token_secret']);
if (isset($token['user_id'])) {
$this->userId = (string) $token['user_id'];
}
if (isset($token['screen_name'])) {
$this->screenName = $token['screen_name'];
}
}
/**
* @param string $userId
*/
public function setUserId(string $userId)
{
$this->userId = $userId;
}
/**
* @return string|null
*/
public function getUserId()
{
return $this->userId;
}
/**
* @return string
*/
public function getScreenName()
{
return $this->screenName;
}
/**
* @return string|null
*/
public function getToken()
{
// It's a key, not a secret
return $this->key;
}
/**
* @return int|null
*/
public function getExpires()
{
// @todo support
return null;
}
}