From ca6a0e70b642b6dfabf98ef2d156e05303811ae3 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:09:37 +0530 Subject: [PATCH] chore: microsoft adapter changes --- src/Auth/OAuth/LinkedIn.php | 2 +- src/Auth/OAuth/Microsoft.php | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Auth/OAuth/LinkedIn.php b/src/Auth/OAuth/LinkedIn.php index 954b9c6ec8..efe6b6bc86 100644 --- a/src/Auth/OAuth/LinkedIn.php +++ b/src/Auth/OAuth/LinkedIn.php @@ -14,7 +14,7 @@ class LinkedIn extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'r_basicprofile', 'r_emailaddress', ]; diff --git a/src/Auth/OAuth/Microsoft.php b/src/Auth/OAuth/Microsoft.php index 6bbf0bad83..5a465d99b4 100644 --- a/src/Auth/OAuth/Microsoft.php +++ b/src/Auth/OAuth/Microsoft.php @@ -14,6 +14,11 @@ class Microsoft extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['offline_access', 'user.read']; + /** * @return string */ @@ -27,13 +32,14 @@ class Microsoft extends OAuth */ public function getLoginURL(): string { - return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&state='.urlencode(json_encode($this->state)). - '&scope=offline_access+user.read'. - '&response_type=code'. - '&response_mode=query'; + return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'state'=> json_encode($this->state), + 'scope'=> implode(' ', $this->getScopes()), + 'response_type' => 'code', + 'response_mode' => 'query' + ]); } /** @@ -49,12 +55,14 @@ class Microsoft extends OAuth 'POST', 'https://login.microsoftonline.com/common/oauth2/v2.0/token', $headers, - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&scope=offline_access+user.read'. - '&grant_type=authorization_code' + http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true);