fix: scopes

This commit is contained in:
Chirag Aggarwal 2025-01-17 07:05:31 +00:00
parent 779510a605
commit 5d3071e084

View file

@ -20,10 +20,9 @@ class Slack extends OAuth2
* @var array * @var array
*/ */
protected array $scopes = [ protected array $scopes = [
'identity.avatar', 'openid',
'identity.basic', 'email',
'identity.email', 'profile',
'identity.team'
]; ];
/** /**
@ -42,7 +41,7 @@ class Slack extends OAuth2
// https://api.slack.com/authentication/oauth-v2 // https://api.slack.com/authentication/oauth-v2
return 'https://slack.com/oauth/v2/authorize?' . \http_build_query([ return 'https://slack.com/oauth/v2/authorize?' . \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope' => \implode(',', $this->getScopes()), 'user_scope' => \implode(',', $this->getScopes()),
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state' => \json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
@ -65,6 +64,10 @@ class Slack extends OAuth2
'redirect_uri' => $this->callback 'redirect_uri' => $this->callback
]) ])
), true); ), true);
if (!$this->tokens['ok']) {
throw new \Exception('Error in fetching access token.');
}
} }
return $this->tokens; return $this->tokens;
@ -160,7 +163,12 @@ class Slack extends OAuth2
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request( $user = $this->request(
'GET', 'GET',
'https://slack.com/api/users.identity?token=' . \urlencode($accessToken) 'https://slack.com/api/users.identity',
[
'headers' => [
'Authorization' => 'Bearer ' . $accessToken
]
]
); );
$this->user = \json_decode($user, true); $this->user = \json_decode($user, true);