Skip to content

Commit

Permalink
added request to obtain a new access token with refresh token.
Browse files Browse the repository at this point in the history
  • Loading branch information
gassan committed Apr 22, 2022
1 parent d3bbee5 commit 19855c4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ protected function makeAccessTokenRequest(string $code): RequestInterface
;
}

/**
* @param string $refreshToken
* @return RequestInterface
*/
protected function makeRefreshAccessTokenRequest(string $refreshToken): RequestInterface
{
$parameters = [
'refresh_token' => $refreshToken,
'client_id' => $this->consumer->getKey(),
'client_secret' => $this->consumer->getSecret(),
'grant_type' => 'refresh_token',
];

return $this->httpStack->createRequest($this->requestHttpMethod, $this->getRequestTokenUri())
->withHeader('Content-Type', 'application/x-www-form-urlencoded')
->withBody($this->httpStack->createStream(http_build_query($parameters, '', '&')))
;
}

/**
* @param string $code
* @return AccessToken
Expand All @@ -132,6 +151,24 @@ public function getAccessToken(string $code): AccessToken
return $this->parseToken($response->getBody()->getContents());
}


/**
* @param string $refreshToken
*
* @return AccessToken
* @throws InvalidAccessToken
* @throws InvalidResponse
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public function refreshAccessToken(string $refreshToken): AccessToken
{
$response = $this->executeRequest(
$this->makeRefreshAccessTokenRequest($refreshToken)
);

return $this->parseToken($response->getBody()->getContents());
}

/**
* @param array $parameters
* @return AccessToken
Expand Down

0 comments on commit 19855c4

Please sign in to comment.