From d2a19207c2469a6d954f3858df0f9e79cbcf4b70 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 20:38:46 +0530 Subject: [PATCH] chore: gitlab adapter fixes --- src/Auth/OAuth/Gitlab.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Auth/OAuth/Gitlab.php b/src/Auth/OAuth/Gitlab.php index fbc6df60fa..60f6656797 100644 --- a/src/Auth/OAuth/Gitlab.php +++ b/src/Auth/OAuth/Gitlab.php @@ -14,6 +14,11 @@ class Gitlab extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['read_user']; + /** * @return string */ @@ -27,12 +32,13 @@ class Gitlab extends OAuth */ public function getLoginURL(): string { - return 'https://gitlab.com/oauth/authorize?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&scope=read_user'. - '&state='.urlencode(json_encode($this->state)). - '&response_type=code'; + return 'https://gitlab.com/oauth/authorize?'.http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state), + 'response_type' => 'code' + ]); } /** @@ -44,12 +50,13 @@ class Gitlab extends OAuth { $accessToken = $this->request( 'POST', - 'https://gitlab.com/oauth/token?'. - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&grant_type=authorization_code' + 'https://gitlab.com/oauth/token?'.http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback, + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true);