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
gguseynov committed Sep 18, 2020
1 parent 896822a commit da112b1
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 da112b1

Please sign in to comment.