From 4d4745ccd29b5a9f9808612318a7709284222ce5 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:42:41 +0530 Subject: [PATCH] chore: refactoring OAuth Adapters --- src/Auth/OAuth/Apple.php | 5 ++++- src/Auth/OAuth/Discord.php | 4 ++-- src/Auth/OAuth/Facebook.php | 4 +++- src/Auth/OAuth/GitHub.php | 4 +++- src/Auth/OAuth/Gitlab.php | 4 +++- src/Auth/OAuth/Google.php | 5 ++++- src/Auth/OAuth/Microsoft.php | 5 ++++- src/Auth/OAuth/Mock.php | 24 +++++++++++++++++++----- src/Auth/OAuth/Slack.php | 7 ++++++- src/Auth/OAuth/Spotify.php | 4 ++-- src/Auth/OAuth/Twitch.php | 4 ++-- src/Auth/OAuth/Vk.php | 14 +++++++++----- src/Auth/OAuth/Yahoo.php | 4 ++-- 13 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/Auth/OAuth/Apple.php b/src/Auth/OAuth/Apple.php index 1157695570..3a5de8ebdc 100644 --- a/src/Auth/OAuth/Apple.php +++ b/src/Auth/OAuth/Apple.php @@ -17,7 +17,10 @@ class Apple extends OAuth /** * @var array */ - protected $scopes = ["name", "email"]; + protected $scopes = [ + "name", + "email" + ]; /** * @return string diff --git a/src/Auth/OAuth/Discord.php b/src/Auth/OAuth/Discord.php index b23653e992..54cf5546b6 100644 --- a/src/Auth/OAuth/Discord.php +++ b/src/Auth/OAuth/Discord.php @@ -20,7 +20,7 @@ class Discord extends OAuth protected $user = []; - protected $scope = [ + protected $scopes = [ 'identify', 'email' ]; @@ -42,7 +42,7 @@ class Discord extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback ]); diff --git a/src/Auth/OAuth/Facebook.php b/src/Auth/OAuth/Facebook.php index 719d6db166..c3c348e493 100644 --- a/src/Auth/OAuth/Facebook.php +++ b/src/Auth/OAuth/Facebook.php @@ -19,7 +19,9 @@ class Facebook extends OAuth /** * @var array */ - protected $scopes = ['email']; + protected $scopes = [ + 'email' + ]; /** * @return string diff --git a/src/Auth/OAuth/GitHub.php b/src/Auth/OAuth/GitHub.php index 9eb0ca48f5..e0e056930d 100644 --- a/src/Auth/OAuth/GitHub.php +++ b/src/Auth/OAuth/GitHub.php @@ -14,7 +14,9 @@ class Github extends OAuth /** * @var array */ - protected $scopes = ['user:email']; + protected $scopes = [ + 'user:email' + ]; /** * @return string diff --git a/src/Auth/OAuth/Gitlab.php b/src/Auth/OAuth/Gitlab.php index 60f6656797..d74e97a766 100644 --- a/src/Auth/OAuth/Gitlab.php +++ b/src/Auth/OAuth/Gitlab.php @@ -17,7 +17,9 @@ class Gitlab extends OAuth /** * @var array */ - protected $scopes = ['read_user']; + protected $scopes = [ + 'read_user' + ]; /** * @return string diff --git a/src/Auth/OAuth/Google.php b/src/Auth/OAuth/Google.php index 28d4072299..cad8c537d8 100644 --- a/src/Auth/OAuth/Google.php +++ b/src/Auth/OAuth/Google.php @@ -18,7 +18,10 @@ class Google extends OAuth /** * @var array */ - protected $scopes = ['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile']; + protected $scopes = [ + 'https://www.googleapis.com/auth/userinfo.email', + 'https://www.googleapis.com/auth/userinfo.profile' + ]; /** * @var array diff --git a/src/Auth/OAuth/Microsoft.php b/src/Auth/OAuth/Microsoft.php index 5a465d99b4..c2c99a38d7 100644 --- a/src/Auth/OAuth/Microsoft.php +++ b/src/Auth/OAuth/Microsoft.php @@ -17,7 +17,10 @@ class Microsoft extends OAuth /** * @var array */ - protected $scopes = ['offline_access', 'user.read']; + protected $scopes = [ + 'offline_access', + 'user.read' + ]; /** * @return string diff --git a/src/Auth/OAuth/Mock.php b/src/Auth/OAuth/Mock.php index 004836e0e9..4c99ee6404 100644 --- a/src/Auth/OAuth/Mock.php +++ b/src/Auth/OAuth/Mock.php @@ -11,6 +11,13 @@ class Mock extends OAuth */ protected $version = 'v1'; + /** + * @var array + */ + protected $scopes = [ + 'email' + ]; + /** * @var array */ @@ -29,7 +36,12 @@ class Mock extends OAuth */ public function getLoginURL():string { - return 'http://localhost/'.$this->version.'/oauth?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=email&state='.urlencode(json_encode($this->state)); + return 'http://localhost/'.$this->version.'/oauth?'. http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state) + ]); } /** @@ -42,10 +54,12 @@ class Mock extends OAuth $accessToken = $this->request( 'GET', 'http://localhost/'.$this->version.'/oauth/token?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&client_secret='.urlencode($this->appSecret). - '&code='.urlencode($code) + http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'client_secret' => $this->appSecret, + 'code' => $code + ]) ); $accessToken = json_decode($accessToken, true); // diff --git a/src/Auth/OAuth/Slack.php b/src/Auth/OAuth/Slack.php index a9f7dca135..3458e743b6 100644 --- a/src/Auth/OAuth/Slack.php +++ b/src/Auth/OAuth/Slack.php @@ -14,7 +14,12 @@ class Slack extends OAuth /** * @var array */ - protected $scopes = ['identity.avatar', 'identity.basic', 'identity.email','identity.team']; + protected $scopes = [ + 'identity.avatar', + 'identity.basic', + 'identity.email', + 'identity.team' + ]; /** * @return string diff --git a/src/Auth/OAuth/Spotify.php b/src/Auth/OAuth/Spotify.php index 84cd9d0151..92c366026f 100644 --- a/src/Auth/OAuth/Spotify.php +++ b/src/Auth/OAuth/Spotify.php @@ -23,7 +23,7 @@ class Spotify extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'user-read-email', ]; @@ -49,7 +49,7 @@ class Spotify extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, 'state' => json_encode($this->state) ]); diff --git a/src/Auth/OAuth/Twitch.php b/src/Auth/OAuth/Twitch.php index b9455bd58a..e5ecb5b142 100644 --- a/src/Auth/OAuth/Twitch.php +++ b/src/Auth/OAuth/Twitch.php @@ -23,7 +23,7 @@ class Twitch extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'user:read:email', ]; @@ -49,7 +49,7 @@ class Twitch extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, 'force_verify' => true, 'state' => json_encode($this->state) diff --git a/src/Auth/OAuth/Vk.php b/src/Auth/OAuth/Vk.php index 2fbc9f9b67..1878fbd348 100644 --- a/src/Auth/OAuth/Vk.php +++ b/src/Auth/OAuth/Vk.php @@ -20,7 +20,10 @@ class Vk extends OAuth /** * @var array */ - protected $scopes = ['openid' ,'email']; + protected $scopes = [ + 'openid', + 'email' + ]; /** * @var string @@ -144,10 +147,11 @@ class Vk extends OAuth if (empty($this->user['name'])) { $user = $this->request( 'GET', - 'https://api.vk.com/method/users.get?'. - 'v='.urlencode($this->version). - '&fields=id,name,email,first_name,last_name'. - '&access_token='.urlencode($accessToken) + 'https://api.vk.com/method/users.get?'. http_build_query([ + 'v' => $this->version, + 'fields' => 'id,name,email,first_name,last_name', + 'access_token' => $accessToken + ]) ); $user = json_decode($user, true); diff --git a/src/Auth/OAuth/Yahoo.php b/src/Auth/OAuth/Yahoo.php index c14e4c6650..84aa596684 100644 --- a/src/Auth/OAuth/Yahoo.php +++ b/src/Auth/OAuth/Yahoo.php @@ -23,7 +23,7 @@ class Yahoo extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'sdct-r', 'sdpp-w', ]; @@ -61,7 +61,7 @@ class Yahoo extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, 'state' => json_encode($this->state) ]);