|
16 | 16 | use chillerlan\HTTP\Psr7\{Request, Response}; |
17 | 17 | use chillerlan\OAuth\Core\{AccessToken, ClientCredentials, CSRFToken, OAuth2Interface, ProviderException, TokenRefresh}; |
18 | 18 | use chillerlan\OAuth\OAuthException; |
19 | | -use Psr\Http\Client\ClientInterface; |
20 | | -use Psr\Http\Message\{RequestInterface, ResponseInterface}; |
21 | 19 |
|
22 | 20 | /** |
23 | 21 | * @property \chillerlan\OAuth\Core\OAuth2Interface $provider |
24 | 22 | */ |
25 | 23 | abstract class OAuth2ProviderTestAbstract extends ProviderTestAbstract{ |
26 | 24 |
|
27 | 25 | protected $responses = [ |
28 | | - '/oauth2/access_token' => [ |
29 | | - 'access_token' => 'test_access_token', |
30 | | - 'expires_in' => 3600, |
31 | | - 'state' => 'test_state', |
32 | | - ], |
33 | | - '/oauth2/refresh_token' => [ |
34 | | - 'access_token' => 'test_refreshed_access_token', |
35 | | - 'expires_in' => 60, |
36 | | - 'state' => 'test_state', |
37 | | - ], |
38 | | - '/oauth2/client_credentials' => [ |
39 | | - 'access_token' => 'test_client_credentials_token', |
40 | | - 'expires_in' => 30, |
41 | | - 'state' => 'test_state', |
42 | | - ], |
43 | | - '/oauth2/api/request' => [ |
44 | | - 'data' => 'such data! much wow!' |
45 | | - ] |
| 26 | + '/oauth2/access_token' => '{"access_token":"test_access_token","expires_in":3600,"state":"test_state"}', |
| 27 | + '/oauth2/refresh_token' => '{"access_token":"test_refreshed_access_token","expires_in":60,"state":"test_state"}', |
| 28 | + '/oauth2/client_credentials' => '{"access_token":"test_client_credentials_token","expires_in":30,"state":"test_state"}', |
| 29 | + '/oauth2/api/request' => '{"data":"such data! much wow!"}', |
46 | 30 | ]; |
47 | 31 |
|
48 | 32 | protected function setUp():void{ |
49 | 33 | parent::setUp(); |
50 | 34 |
|
51 | 35 | $this->setProperty($this->provider, 'apiURL', 'https://localhost/oauth2/api'); |
52 | 36 | $this->setProperty($this->provider, 'accessTokenURL', 'https://localhost/oauth2/access_token'); |
| 37 | + $this->setProperty($this->provider, 'refreshTokenURL', 'https://localhost/oauth2/refresh_token'); |
| 38 | + $this->setProperty($this->provider, 'clientCredentialsTokenURL', 'https://localhost/oauth2/client_credentials'); |
53 | 39 |
|
54 | | - if($this->provider instanceof TokenRefresh){ |
55 | | - $this->setProperty($this->provider, 'refreshTokenURL', 'https://localhost/oauth2/refresh_token'); |
56 | | - } |
57 | | - |
58 | | - if($this->provider instanceof ClientCredentials){ |
59 | | - $this->setProperty($this->provider, 'clientCredentialsTokenURL', 'https://localhost/oauth2/client_credentials'); |
60 | | - } |
61 | | - |
62 | | - if($this->provider instanceof CSRFToken){ |
63 | | - $this->storage->storeCSRFState($this->provider->serviceName, 'test_state'); |
64 | | - } |
65 | | - |
66 | | - } |
67 | | - |
68 | | - /** |
69 | | - * @return \Psr\Http\Client\ClientInterface |
70 | | - */ |
71 | | - protected function initHttp():ClientInterface{ |
72 | | - return new class($this->responses, $this->logger) extends ProviderTestHttpClient{ |
73 | | - |
74 | | - public function sendRequest(RequestInterface $request):ResponseInterface{ |
75 | | - $stream = Psr17\create_stream_from_input(json_encode($this->responses[$request->getUri()->getPath()])); |
76 | | - |
77 | | - return $this->logRequest($request, (new Response)->withBody($stream)); |
78 | | - } |
79 | | - |
80 | | - }; |
| 40 | + $this->storage->storeCSRFState($this->provider->serviceName, 'test_state'); |
81 | 41 | } |
82 | 42 |
|
83 | 43 | public function testOAuth2Instance(){ |
|
0 commit comments