|
4 | 4 |
|
5 | 5 | use Drupal\Component\Datetime\TimeInterface; |
6 | 6 | use Drupal\Core\DependencyInjection\AutowireTrait; |
| 7 | +use Drupal\Core\Serialization\Yaml; |
7 | 8 | use Drupal\Core\Url; |
8 | 9 | use Drush\Attributes as CLI; |
9 | 10 | use Drush\Commands\DrushCommands; |
|
12 | 13 | use Symfony\Component\HttpFoundation\Request; |
13 | 14 |
|
14 | 15 | /** |
15 | | - * A Drush commandfile. |
| 16 | + * A Drush command file. |
16 | 17 | */ |
17 | 18 | final class Os2loopCuraLoginCommands extends DrushCommands { |
18 | 19 | use AutowireTrait; |
@@ -53,30 +54,32 @@ public function getLoginUrl( |
53 | 54 | ]; |
54 | 55 | $jwt = JWT::encode($payload, $options['secret'], $options['algorithm']); |
55 | 56 |
|
| 57 | + $routeName = 'os2loop_cura_login.start'; |
56 | 58 | $routeParameters = []; |
57 | 59 | $requestOptions = []; |
58 | 60 | if ($name = $options['get']) { |
59 | 61 | $method = Request::METHOD_GET; |
60 | 62 | $routeParameters[$name] = $jwt; |
| 63 | + if ('jwt' === $name) { |
| 64 | + $routeName = 'os2loop_cura_login.start_get_jwt'; |
| 65 | + } |
61 | 66 | } |
62 | 67 | else { |
63 | 68 | $method = Request::METHOD_POST; |
64 | | - $requestOptions['body'] = ['payload' => $jwt]; |
| 69 | + $requestOptions['form_params'] = ['payload' => $jwt]; |
65 | 70 | } |
66 | | - $url = Url::fromRoute('os2loop_cura_login.start', $routeParameters)->setAbsolute()->toString(TRUE)->getGeneratedUrl(); |
| 71 | + $url = Url::fromRoute($routeName, $routeParameters)->setAbsolute()->toString(TRUE)->getGeneratedUrl(); |
67 | 72 | $this->io()->writeln($method === Request::METHOD_POST |
68 | 73 | ? sprintf('POST\'ing to %s', $url) |
69 | 74 | : sprintf('GET\'ing %s', $url), |
70 | 75 | ); |
71 | | - $request = $this->httpClient->request($method, $url, $requestOptions); |
| 76 | + $response = $this->httpClient->request($method, $url, $requestOptions); |
72 | 77 |
|
73 | | - header('content-type: text/plain'); |
74 | | - echo var_export([ |
75 | | - $url, |
76 | | - $request->getStatusCode(), |
77 | | - $request->getBody()->getContents(), |
78 | | - ], TRUE); |
79 | | - die(__FILE__ . ':' . __LINE__ . ':' . __METHOD__); |
| 78 | + $this->io()->writeln(Yaml::encode([ |
| 79 | + 'status' => $response->getStatusCode(), |
| 80 | + 'headers' => Yaml::encode($response->getHeaders()), |
| 81 | + 'body' => $response->getBody()->getContents(), |
| 82 | + ])); |
80 | 83 | } |
81 | 84 |
|
82 | 85 | } |
0 commit comments