1 | <?php |
||
27 | class Server |
||
28 | { |
||
29 | /** |
||
30 | * @var EntityCollection |
||
31 | */ |
||
32 | protected $grantExtensions; |
||
33 | |||
34 | /** |
||
35 | * @var ApplicationLoaderInterface |
||
36 | */ |
||
37 | protected $applicationLoader; |
||
38 | |||
39 | /** |
||
40 | * @var AccessTokenLoaderInterface |
||
41 | */ |
||
42 | protected $accessTokenLoader; |
||
43 | |||
44 | /** |
||
45 | * @var EventDispatcherInterface |
||
46 | */ |
||
47 | protected $eventDispatcher; |
||
48 | |||
49 | /** |
||
50 | * @var RandomTokenGenerator |
||
51 | */ |
||
52 | protected $randomTokenGenerator; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $tokenOptions; |
||
58 | |||
59 | /** |
||
60 | * Construct. |
||
61 | * |
||
62 | * @param EventDispatcherInterface $eventDispatcher |
||
63 | * @param ApplicationLoaderInterface $applicationLoader |
||
64 | * @param AccessTokenLoaderInterface $accessTokenLoader |
||
65 | * @param RandomTokenGenerator $randomTokenGenerator |
||
66 | * @param array $tokenOptions |
||
67 | * @param array $grantExtensions |
||
68 | */ |
||
69 | 18 | public function __construct( |
|
70 | EventDispatcherInterface $eventDispatcher, |
||
71 | ApplicationLoaderInterface $applicationLoader, |
||
72 | AccessTokenLoaderInterface $accessTokenLoader, |
||
73 | RandomTokenGenerator $randomTokenGenerator, |
||
74 | array $tokenOptions, |
||
75 | array $grantExtensions = array() |
||
76 | ) { |
||
77 | 18 | $this->applicationLoader = $applicationLoader; |
|
78 | 18 | $this->accessTokenLoader = $accessTokenLoader; |
|
79 | 18 | $this->eventDispatcher = $eventDispatcher; |
|
80 | 18 | $this->randomTokenGenerator = $randomTokenGenerator; |
|
81 | |||
82 | 18 | $tokenOptionsResolver = new OptionsResolver(); |
|
83 | 18 | $tokenOptionsResolver->setDefaults(array( |
|
84 | 18 | 'access_token_class' => AccessToken::class, |
|
85 | 18 | 'access_token_ttl' => AccessTokenInterface::DEFAULT_TTL, |
|
86 | 9 | 'refresh_token_class' => RefreshToken::class, |
|
87 | 18 | 'refresh_token_ttl' => RefreshTokenInterface::DEFAULT_TTL, |
|
88 | 9 | )); |
|
89 | |||
90 | 18 | $this->tokenOptions = $tokenOptionsResolver->resolve($tokenOptions); |
|
91 | |||
92 | 18 | $this->grantExtensions = new EntityCollection(); |
|
93 | 18 | foreach ($grantExtensions as $grantType => $extension) { |
|
94 | 18 | $this->registerGrantExtension($grantType, $extension); |
|
95 | 9 | } |
|
96 | 18 | } |
|
97 | |||
98 | /** |
||
99 | * Register an extension under given grant type. |
||
100 | * |
||
101 | * @param string $grantType |
||
102 | * @param GrantExtensionInterface $extension |
||
103 | */ |
||
104 | 18 | public function registerGrantExtension($grantType, GrantExtensionInterface $extension) |
|
108 | |||
109 | /** |
||
110 | * Validate given request parameters and build a |
||
111 | * LoginAttempt object with it. |
||
112 | * |
||
113 | * @param array $data |
||
114 | * @param array $headers |
||
115 | * @param array $query |
||
116 | * |
||
117 | * @return LoginAttempt |
||
118 | */ |
||
119 | 18 | protected function createLoginAttempt(array $data, array $headers, array $query) |
|
147 | |||
148 | /** |
||
149 | * Loads application for given login attempt. |
||
150 | * |
||
151 | * @param LoginAttempt $loginAttempt |
||
152 | * |
||
153 | * @return ApplicationInterface |
||
154 | * |
||
155 | * @throws InvalidGrantException |
||
156 | */ |
||
157 | 14 | protected function loadApplication(LoginAttempt $loginAttempt) |
|
172 | |||
173 | /** |
||
174 | * Runs grant extension to load accounts. |
||
175 | * |
||
176 | * @param ApplicationInterface $application |
||
177 | * @param LoginAttempt $loginAttempt |
||
178 | * |
||
179 | * @return AccountInterface |
||
180 | * |
||
181 | * @throws \InvalidArgumentException |
||
182 | * @throws UnknownGrantTypeException |
||
183 | */ |
||
184 | 12 | protected function loadAccount( |
|
194 | |||
195 | /** |
||
196 | * Grant given credentials, or throws an exception if invalid |
||
197 | * credentials for application or account. |
||
198 | * |
||
199 | * @param array $data login request data |
||
200 | * @param array $headers optionnal login request headers |
||
201 | * @param array $query optionnal login request query |
||
202 | * |
||
203 | * @return AccessTokenInterface |
||
204 | */ |
||
205 | 18 | public function grant(array $data, array $headers = array(), array $query = array()) |
|
248 | |||
249 | /** |
||
250 | * Tests if given hash match a valid AccessToken. |
||
251 | * |
||
252 | * @param string $hash |
||
253 | * |
||
254 | * @return AccessToken |
||
255 | * |
||
256 | * @throws InvalidAccessTokenException |
||
257 | */ |
||
258 | public function check($hash) |
||
266 | } |
||
267 |