Skip to content

Commit

Permalink
Merge pull request #37 from sandervanhooft/override_get_access_token
Browse files Browse the repository at this point in the history
Override getAccessToken
  • Loading branch information
Naoray authored Feb 20, 2025
2 parents 61f4f5d + 87f092a commit d7bbf16
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
"require": {
"php": "^7.4|^8.0",
"league/oauth2-client": "~2.7.0"
"league/oauth2-client": "^2.7"
},
"require-dev": {
"phpunit/phpunit": "^9.6|^10.0",
Expand Down
44 changes: 44 additions & 0 deletions src/Provider/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Token\AccessTokenInterface;
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use Psr\Http\Message\ResponseInterface;
use UnexpectedValueException;

class Mollie extends AbstractProvider
{
Expand Down Expand Up @@ -213,6 +215,48 @@ public function revokeToken($type, $token): ResponseInterface
]);
}

/**
* Requests an access token using a specified grant and option set.
*
* @param mixed $grant
* @param array<string, mixed> $options
* @return AccessTokenInterface
* @throws IdentityProviderException
* @throws UnexpectedValueException
*/
public function getAccessToken($grant, array $options = [])
{
$grant = $this->verifyGrant($grant);

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

$params = [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $this->redirectUri,
];

if (!empty($this->pkceCode)) {
$params['code_verifier'] = $this->pkceCode;
}

$params = $grant->prepareRequestParameters($params, $options);
$request = $this->getAccessTokenRequest($params);
$response = $this->getParsedResponse($request);
if (false === is_array($response)) {
throw new UnexpectedValueException(
'Invalid response received from Authorization Server. Expected JSON.'
);
}
$prepared = $this->prepareAccessTokenResponse($response);
$token = $this->createAccessToken($prepared, $grant);

return $token;
}

/**
* Sends a token revocation request and returns an response instance.
*
Expand Down

0 comments on commit d7bbf16

Please sign in to comment.