1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Tests\Controller; |
13
|
|
|
|
14
|
|
|
use Lakion\ApiTestCase\JsonApiTestCase; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Łukasz Chruściel <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
final class OauthTokenApiTest extends JsonApiTestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
|
public function it_provides_an_access_token() |
26
|
|
|
{ |
27
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
28
|
|
|
|
29
|
|
|
$data = |
30
|
|
|
<<<EOT |
31
|
|
|
{ |
32
|
|
|
"client_id": "client_id", |
33
|
|
|
"client_secret": "secret", |
34
|
|
|
"grant_type": "password", |
35
|
|
|
"username": "[email protected]", |
36
|
|
|
"password": "sylius" |
37
|
|
|
} |
38
|
|
|
EOT; |
39
|
|
|
|
40
|
|
|
$this->client->request('POST', '/api/oauth/v2/token', [], [], ['CONTENT_TYPE' => 'application/json'], $data); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
$response = $this->client->getResponse(); |
44
|
|
|
$this->assertResponse($response, 'authentication/new_access_token', Response::HTTP_OK); |
45
|
|
|
} |
46
|
|
|
/** |
47
|
|
|
* @test |
48
|
|
|
*/ |
49
|
|
|
public function it_allows_to_refresh_an_access_token() |
50
|
|
|
{ |
51
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
52
|
|
|
|
53
|
|
|
$data = |
54
|
|
|
<<<EOT |
55
|
|
|
{ |
56
|
|
|
"client_id": "client_id", |
57
|
|
|
"client_secret": "secret", |
58
|
|
|
"grant_type": "refresh_token", |
59
|
|
|
"refresh_token": "SampleRefreshTokenODllODY4ZTQyOThlNWIyMjA1ZDhmZjE1ZDYyMGMwOTUxOWM2NGFmNGRjNjQ2NDBhMDVlNGZjMmQ0YzgyNDM2Ng" |
60
|
|
|
} |
61
|
|
|
EOT; |
62
|
|
|
|
63
|
|
|
$this->client->request('POST', '/api/oauth/v2/token', [], [], ['CONTENT_TYPE' => 'application/json'], $data); |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
$response = $this->client->getResponse(); |
67
|
|
|
$this->assertResponse($response, 'authentication/new_access_token', Response::HTTP_OK); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|