Skip to content

Commit

Permalink
Merge pull request #26 from eventfarm/feature/add-public-functionalit…
Browse files Browse the repository at this point in the history
…y-to-restforce-to-refresh-the-user-token

Updated restforce so that a user can refresh a token
  • Loading branch information
kevinthrailkill authored May 3, 2021
2 parents f52382e + 4063102 commit df13a70
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Rest/OAuthRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public function patchJson(
);
}

public function refreshToken(): OAuthAccessToken
{
$refreshToken = $this->oAuthAccessToken->getRefreshToken();
$refreshedToken = $this->getRefreshToken($refreshToken);
$this->oAuthAccessToken = $refreshedToken;
return $refreshedToken;
}


private function setParamsFromAccessToken(): void
{
$this->apiRestClient->setBaseUriForRestClient($this->getOAuthAccessToken()->getInstanceUrl());
Expand Down
2 changes: 2 additions & 0 deletions src/Rest/RestClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public function patchJson(
array $headers = [],
?float $timeoutSeconds = null
): ResponseInterface;

public function refreshToken(): OAuthAccessToken;
}
5 changes: 5 additions & 0 deletions src/Restforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public function query(string $queryString): ResponseInterface
]);
}

public function refreshToken(): OAuthAccessToken
{
return $this->getOAuthRestClient()->refreshToken();
}

public function userInfo(): ResponseInterface
{
return $this->getOAuthRestClient()->get(self::USER_INFO_ENDPOINT);
Expand Down
2 changes: 2 additions & 0 deletions src/RestforceInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace EventFarm\Restforce;

use EventFarm\Restforce\Rest\OAuthAccessToken;
use Psr\Http\Message\ResponseInterface;

interface RestforceInterface
Expand All @@ -13,4 +14,5 @@ public function update(string $sobjectType, string $sobjectId, array $data): Res
public function describe(string $sobjectType): ResponseInterface;
public function find(string $sobjectType, string $sobjectId, array $fields = []): ResponseInterface;
public function getNext(string $url): ResponseInterface;
public function refreshToken(): OAuthAccessToken;
}

0 comments on commit df13a70

Please sign in to comment.