Skip to content

Commit

Permalink
Add scope to access token requests
Browse files Browse the repository at this point in the history
  • Loading branch information
liayn committed May 16, 2024
1 parent 004b407 commit b6e966a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# OAuth 2.0 Client Changelog

## x.x.x

* Send scopes with access token request [#1029](https://github.com/thephpleague/oauth2-client/issues/1029)

## 2.7.0

_Released: 2023-04-16_
Expand Down
9 changes: 9 additions & 0 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ public function getAccessToken($grant, array $options = [])
{
$grant = $this->verifyGrant($grant);

if (empty($options['scope'])) {
$options['scope'] = $this->getDefaultScopes();
}

if (is_array($options['scope'])) {
$separator = $this->getScopeSeparator();
$options['scope'] = implode($separator, $options['scope']);
}

$params = [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
Expand Down
3 changes: 2 additions & 1 deletion test/src/Grant/PasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ protected function getParamExpectation()
return !empty($body['grant_type'])
&& $body['grant_type'] === 'password'
&& !empty($body['username'])
&& !empty($body['password']);
&& !empty($body['password'])
&& !empty($body['scope']);
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/src/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public function testGetAccessToken($method)
->once()
->with(
['client_id' => 'mock_client_id', 'client_secret' => 'mock_secret', 'redirect_uri' => 'none'],
['code' => 'mock_authorization_code']
['code' => 'mock_authorization_code', 'scope' => 'test']
)
->andReturn([]);

Expand Down

0 comments on commit b6e966a

Please sign in to comment.