diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index 82592c2..fb5573a 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -1,5 +1,6 @@ request->session()->set('oauth_state', $state); - $oAuth = new GoogleOAuth(); + $oAuth = new GoogleOAuth(new Request()); $url = $oAuth->getDialogUrl($state, $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('login-google-action')->generateLink()); return new Redirect($url, IRedirect::TEMPORARY); @@ -147,7 +148,7 @@ class LoginController return new HtmlContent('login/google_login', $data); } - $oAuth = new GoogleOAuth(); + $oAuth = new GoogleOAuth(new Request()); $tokenData = $oAuth->getToken($this->request->query('code'), $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('login-google-action')->generateLink()); if (!isset($tokenData['id_token'])) { diff --git a/src/Http/Request.php b/src/Http/Request.php index 2e5426a..9f1a05b 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -1,11 +1,10 @@ url = $url; $this->method = $method; } + public function setUrl(string $url): void + { + $this->url = $url; + } + + public function setMethod(int $method): void + { + $this->method = $method; + } + public function setQuery($query) { if (is_string($query)) { @@ -34,7 +43,7 @@ class Request $this->headers = array_merge($this->headers, $headers); } - public function send(): Response + public function send(): IResponse { $ch = curl_init(); diff --git a/src/Http/Response.php b/src/Http/Response.php index 9bee447..65958b0 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -1,6 +1,8 @@ request = $request; + } + public function getDialogUrl(string $state, string $redirectUrl): string { $oauthParams = [ @@ -32,9 +39,10 @@ class GoogleOAuth 'grant_type' => 'authorization_code', ]; - $request = new Request(self::$tokenUrlBase, Request::HTTP_POST); - $request->setQuery($tokenParams); - $response = $request->send(); + $this->request->setUrl(self::$tokenUrlBase); + $this->request->setMethod(IRequest::HTTP_POST); + $this->request->setQuery($tokenParams); + $response = $this->request->send(); return json_decode($response->getBody(), true); }