Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 9ac7dc5

Browse files
committed
:octocat: OAuthProvider: clean up PSR-18 sendRequest()
1 parent 26ba961 commit 9ac7dc5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/Core/OAuthProvider.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -375,28 +375,28 @@ protected function getRequestTarget(string $uri):string{
375375
* @inheritDoc
376376
* @throws \chillerlan\OAuth\Core\InvalidAccessTokenException
377377
*/
378-
public function sendRequest(RequestInterface $request):ResponseInterface{
379-
380-
// get authorization only if we request the provider API
381-
if(str_starts_with((string)$request->getUri(), $this->apiURL)){
382-
$token = $this->storage->getAccessToken($this->serviceName);
378+
final public function sendRequest(RequestInterface $request):ResponseInterface{
379+
// get authorization only if we request the provider API,
380+
// shortcut reroute to the http client otherwise.
381+
// avoid sending bearer tokens to unknown hosts
382+
if(!str_starts_with((string)$request->getUri(), $this->apiURL)){
383+
return $this->http->sendRequest($request);
384+
}
383385

384-
// attempt to refresh an expired token
385-
if($token->isExpired() || $token->expires === $token::EOL_UNKNOWN){
386+
$token = $this->storage->getAccessToken($this->serviceName);
386387

387-
if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh){
388-
$token = $this->refreshAccessToken($token);
389-
}
390-
else{
391-
throw new InvalidAccessTokenException;
392-
}
388+
// attempt to refresh an expired token
389+
if($token->isExpired()){
393390

391+
if(!$this instanceof TokenRefresh || $this->options->tokenAutoRefresh !== true){
392+
throw new InvalidAccessTokenException;
394393
}
395394

396-
$request = $this->getRequestAuthorization($request, $token);
397-
final public function sendRequest(RequestInterface $request):ResponseInterface{
395+
$token = $this->refreshAccessToken($token);
398396
}
399397

398+
$request = $this->getRequestAuthorization($request, $token);
399+
400400
return $this->http->sendRequest($request);
401401
}
402402

0 commit comments

Comments
 (0)