Skip to content

Commit b7260da

Browse files
authored
Move credential refreshing to the resolution of the credential manager
1 parent 5173788 commit b7260da

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/XeroServiceProvider.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ public function register()
5252
});
5353

5454
$this->app->bind(OauthCredentialManager::class, function(Application $app) {
55-
return $app->make(config('xero.credential_store'));
55+
$credentials = $app->make(config('xero.credential_store'));
56+
57+
if ($credentials->exists() && $credentials->isExpired()) {
58+
$credentials->refresh();
59+
}
60+
61+
return $credentials;
5662
});
5763

5864
$this->app->bind(Configuration::class, function (Application $app) {
@@ -61,10 +67,6 @@ public function register()
6167
$config->setHost(config('xero.api_host'));
6268

6369
if ($credentials->exists()) {
64-
if ($credentials->isExpired()) {
65-
$credentials->refresh();
66-
}
67-
6870
$config->setAccessToken($credentials->getAccessToken());
6971
}
7072

0 commit comments

Comments
 (0)