Skip to content

Commit 37f02f3

Browse files
committed
WIP
1 parent c07855e commit 37f02f3

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

config/config.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
return [
44

5+
'api_host' => 'https://api.xero.com/api.xro/2.0',
6+
57
'oauth' => [
68
/************************************************************************
79
* Client ID provided by Xero when registering your application
@@ -29,6 +31,11 @@
2931
'offline_access',
3032
],
3133

34+
/************************************************************************
35+
* Url to redirect to upon success
36+
************************************************************************/
37+
'redirect_on_success' => 'xero.auth.success',
38+
3239
/************************************************************************
3340
* Url for Xero to redirect to upon granting access
3441
* Unless you wish to change the default behaviour you should not need to

src/Controllers/AuthorizationCallbackController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __invoke(Request $request, OauthCredentialManager $oauth, Identi
3939

4040
public function onSuccess()
4141
{
42-
return Redirect::route(config('xero.oauth.on_success'));
42+
return Redirect::route(config('xero.oauth.redirect_on_success'));
4343
}
4444

4545
public function onFailure(\throwable $e)

src/Controllers/AuthorizationController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class AuthorizationController extends Controller
1010
{
1111
public function __invoke(Redirector $redirect, OauthCredentialManager $oauth)
1212
{
13-
1413
return $redirect->to($oauth->getAuthorizationUrl());
1514
}
1615

src/OauthCredentialManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public function store(AccessTokenInterface $token, $tenantId = null)
9696
$this->cache->set($this->cacheKey, [
9797
'token' => $token->getToken(),
9898
'refresh_token' => $token->getRefreshToken(),
99-
'id_token' => $token->getValues(),
100-
'expires' => $token->getExpires()['id_token'],
99+
'id_token' => $token->getValues()['id_token'],
100+
'expires' => $token->getExpires(),
101101
'tenant_id' => $tenantId ?? $this->data('tenant_id')
102102
]);
103103
}

src/XeroServiceProvider.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ public function register()
4444
]);
4545
});
4646

47-
$this->app->singleton(Configuration::class, function (Application $app, OauthCredentialManager $credentials) {
47+
$this->app->singleton(Configuration::class, function (Application $app) {
48+
$credentials = $app->make(OauthCredentialManager::class);
4849
$config = Configuration::getDefaultConfiguration();
49-
$config->setHost('https://api.xero.com');
50+
$config->setHost(config('xero.api_host'));
5051

5152
if ($credentials->exists()) {
5253
//expires
@@ -65,11 +66,12 @@ public function register()
6566

6667
});
6768

68-
$this->app->singleton(IdentityApi::class, function (Application $app, Configuration $xeroConfig) {
69-
return new IdentityApi(new GuzzleClient(), $xeroConfig);
69+
$this->app->singleton(IdentityApi::class, function (Application $app) {
70+
return new IdentityApi(new GuzzleClient(), $app->make(Configuration::class));
7071
});
7172

72-
$this->app->singleton(AccountingApi::class, function (Application $app, Configuration $xeroConfig) {
73+
$this->app->singleton(AccountingApi::class, function (Application $app) {
74+
return new AccountingApi(new GuzzleClient(), $app->make(Configuration::class));
7375
});
7476
}
7577
}

0 commit comments

Comments
 (0)