-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from helpscout/v2-automatically-refresh-expir…
…ed-token SDK v2: Automatically refresh expired token
- Loading branch information
Showing
9 changed files
with
374 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
require '_credentials.php'; | ||
|
||
use HelpScout\Api\ApiClientFactory; | ||
use HelpScout\Api\Http\Authenticator; | ||
|
||
/** | ||
* The ApiClient can automatically refresh an expired token for you upon a failed request. | ||
* When building the client a callback can be provided that will be executed immediately after | ||
* the new token is issued. | ||
*/ | ||
$client = ApiClientFactory::createClient([], function (Authenticator $authenticator) { | ||
echo 'New token: '.$authenticator->accessToken().PHP_EOL; | ||
}); | ||
|
||
$expiredRefreshToken = ''; | ||
$client = $client->useRefreshToken($appId, $appSecret, $expiredRefreshToken); | ||
|
||
// Try to obtain a customer | ||
$customer = $client->customers()->get(347089737); | ||
var_dump($customer->getFirstEmail()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HelpScout\Api\Http\Auth; | ||
|
||
use HelpScout\Api\Http\Authenticator; | ||
|
||
interface HandlesTokenRefreshes | ||
{ | ||
public function whenTokenRefreshed(Authenticator $authenticator); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.