From efdacd72484a8b84451a6017c2058a34f2aef025 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:14:08 +0530 Subject: [PATCH] chore: fixed slack adapter --- src/Auth/OAuth/Slack.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Auth/OAuth/Slack.php b/src/Auth/OAuth/Slack.php index 120dd4233d..a9f7dca135 100644 --- a/src/Auth/OAuth/Slack.php +++ b/src/Auth/OAuth/Slack.php @@ -11,6 +11,11 @@ class Slack extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['identity.avatar', 'identity.basic', 'identity.email','identity.team']; + /** * @return string */ @@ -25,11 +30,12 @@ class Slack extends OAuth public function getLoginURL():string { // https://api.slack.com/docs/oauth#step_1_-_sending_users_to_authorize_and_or_install - return 'https://slack.com/oauth/authorize'. - '?client_id='.urlencode($this->appID). - '&scope=identity.avatar+identity.basic+identity.email+identity.team'. - '&redirect_uri='.urlencode($this->callback). - '&state='.urlencode(json_encode($this->state)); + return 'https://slack.com/oauth/authorize?'.http_build_query([ + 'client_id'=> $this->appID, + 'scope' => implode(' ', $this->getScopes()), + 'redirect_uri' => $this->callback, + 'state' => json_encode($this->state) + ]); } /** @@ -42,11 +48,12 @@ class Slack extends OAuth // https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token $accessToken = $this->request( 'GET', - 'https://slack.com/api/oauth.access'. - '?client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&code='.urlencode($code). - '&redirect_uri='.urlencode($this->callback) + 'https://slack.com/api/oauth.access?'.http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'code' => $code, + 'redirect_uri' => $this->callback + ]) ); $accessToken = json_decode($accessToken, true); // @@ -118,7 +125,7 @@ class Slack extends OAuth // https://api.slack.com/methods/users.identity $user = $this->request( 'GET', - 'https://slack.com/api/users.identity?token='.urlencode($accessToken), + 'https://slack.com/api/users.identity?token='.urlencode($accessToken) ); $this->user = json_decode($user, true);