1 | <?php namespace nyx\auth\id; |
||
16 | abstract class Identity implements interfaces\Identity |
||
17 | { |
||
18 | /** |
||
19 | * @var string The fully qualified class name of this Identity's Provider. |
||
20 | */ |
||
21 | protected static $provider; |
||
22 | |||
23 | /** |
||
24 | * @var string The unique identifier of the Identity specific to its Provider. |
||
25 | */ |
||
26 | protected $id; |
||
27 | |||
28 | /** |
||
29 | * @var string The username/nickname/display name bound to the Identity. |
||
30 | */ |
||
31 | protected $username; |
||
32 | |||
33 | /** |
||
34 | * @var string The full name bound to the Identity. |
||
35 | */ |
||
36 | protected $name; |
||
37 | |||
38 | /** |
||
39 | * @var string The e-mail address bound to the Identity. |
||
40 | */ |
||
41 | protected $email; |
||
42 | |||
43 | /** |
||
44 | * @var string The avatar URI bound to the Identity. |
||
45 | */ |
||
46 | protected $avatar; |
||
47 | |||
48 | /** |
||
49 | * @var array The raw data about the Identity the Provider made available. |
||
50 | */ |
||
51 | protected $raw; |
||
52 | |||
53 | /** |
||
54 | * @var array The access tokens associated with the Identity. |
||
55 | */ |
||
56 | protected $tokens = []; |
||
57 | |||
58 | /** |
||
59 | * Instantiates a Provider of the appropriate type specific to this Identity. |
||
60 | * |
||
61 | * Utility factory method for requesting consumer data when a specific Provider is needed, without having to |
||
62 | * worry about the underlying implementation and protocols used to access that data. |
||
63 | * |
||
64 | * @param string $clientId The consumer's (application/client) identifier. |
||
65 | * @param string $clientSecret The consumer's (application/client) secret. |
||
66 | * @param string $redirectUrl The consumer's (application/client) callback URL. |
||
67 | * @return interfaces\Provider The created Provider instance. |
||
68 | * @throws \LogicException When the Identity implementation did not define its static $provider property. |
||
69 | */ |
||
70 | public static function provider(string $clientId, string $clientSecret, string $redirectUrl) : interfaces\Provider |
||
78 | |||
79 | /** |
||
80 | * Creates a new Identity instance. |
||
81 | * |
||
82 | * @param auth\interfaces\Token $token The access Token used to retrieve the data about the Identity. |
||
83 | * @param array $data The raw data about the Identity the Provider made available. |
||
84 | * @throws \InvalidArgumentException When the identifier was not mapped to the 'id' property beforehand |
||
85 | * and could not be found in the raw data either. |
||
86 | */ |
||
87 | public function __construct(auth\interfaces\Token $token, array $data) |
||
104 | |||
105 | /** |
||
106 | * {@inheritDoc} |
||
107 | */ |
||
108 | public function getId() : string |
||
112 | |||
113 | /** |
||
114 | * {@inheritDoc} |
||
115 | */ |
||
116 | public function getUsername() : ?string |
||
120 | |||
121 | /** |
||
122 | * {@inheritDoc} |
||
123 | */ |
||
124 | public function getName() : ?string |
||
128 | |||
129 | /** |
||
130 | * {@inheritDoc} |
||
131 | */ |
||
132 | public function getEmail() : ?string |
||
136 | |||
137 | /** |
||
138 | * {@inheritDoc} |
||
139 | */ |
||
140 | public function getAvatar() : ?string |
||
144 | |||
145 | /** |
||
146 | * Returns the raw data about the Identity the Provider made available. |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | public function getRaw() : array |
||
154 | } |
||
155 |