Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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