Skip to content

Commit 19855c4

Browse files
committed
added request to obtain a new access token with refresh token.
1 parent d3bbee5 commit 19855c4

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/OAuth2/AbstractProvider.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ protected function makeAccessTokenRequest(string $code): RequestInterface
116116
;
117117
}
118118

119+
/**
120+
* @param string $refreshToken
121+
* @return RequestInterface
122+
*/
123+
protected function makeRefreshAccessTokenRequest(string $refreshToken): RequestInterface
124+
{
125+
$parameters = [
126+
'refresh_token' => $refreshToken,
127+
'client_id' => $this->consumer->getKey(),
128+
'client_secret' => $this->consumer->getSecret(),
129+
'grant_type' => 'refresh_token',
130+
];
131+
132+
return $this->httpStack->createRequest($this->requestHttpMethod, $this->getRequestTokenUri())
133+
->withHeader('Content-Type', 'application/x-www-form-urlencoded')
134+
->withBody($this->httpStack->createStream(http_build_query($parameters, '', '&')))
135+
;
136+
}
137+
119138
/**
120139
* @param string $code
121140
* @return AccessToken
@@ -132,6 +151,24 @@ public function getAccessToken(string $code): AccessToken
132151
return $this->parseToken($response->getBody()->getContents());
133152
}
134153

154+
155+
/**
156+
* @param string $refreshToken
157+
*
158+
* @return AccessToken
159+
* @throws InvalidAccessToken
160+
* @throws InvalidResponse
161+
* @throws \Psr\Http\Client\ClientExceptionInterface
162+
*/
163+
public function refreshAccessToken(string $refreshToken): AccessToken
164+
{
165+
$response = $this->executeRequest(
166+
$this->makeRefreshAccessTokenRequest($refreshToken)
167+
);
168+
169+
return $this->parseToken($response->getBody()->getContents());
170+
}
171+
135172
/**
136173
* @param array $parameters
137174
* @return AccessToken

0 commit comments

Comments
 (0)