You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
-267Lines changed: 0 additions & 267 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,273 +14,6 @@ You can install this package via composer using the following command:
14
14
composer require webfox/laravel-xero-oauth2
15
15
```
16
16
17
-
The package will automatically register itself.
18
-
19
-
You should add your Xero keys to your `.env` file using the following keys:
20
-
21
-
```
22
-
XERO_CLIENT_ID=
23
-
XERO_CLIENT_SECRET=
24
-
```
25
-
26
-
(on [Xero developer portal](https://developer.xero.com/app/manage)): ***IMPORTANT*** When setting up the application in Xero ensure your redirect url is:
27
-
28
-
```
29
-
https://{your-domain}/xero/auth/callback
30
-
```
31
-
32
-
*(The flow is xero/auth/callback performs the oAuth handshake and stores your token, then redirects you over to your success callback)*
You'll want to set the scopes required for your application in the config file.
43
-
44
-
The default set of scopes are `openid`, `email`, `profile`, `offline_access`, and `accounting.settings`.
45
-
You can see all available scopes on [the official Xero documentation](https://developer.xero.com/documentation/oauth2/scopes).
46
-
47
-
## Using the Package
48
-
49
-
This package registers two bindings into the service container you'll be interested in:
50
-
51
-
*`\XeroAPI\XeroPHP\Api\AccountingApi::class` this is the main api for Xero - see the [xeroapi/xero-php-oauth2 docs](https://github.com/XeroAPI/xero-php-oauth2/tree/master/docs) for usage.
52
-
When you first resolve this dependency if the stored credentials are expired it will automatically refresh the token.
53
-
*`Webfox\Xero\OauthCredentialManager` this is the credential manager - The Accounting API requires we pass through a tenant ID on each request, this class is how you'd access that.
54
-
This is also where we can get information about the authenticating user. See below for an example.
55
-
56
-
*app\Http\Controllers\XeroController.php*
57
-
58
-
```php
59
-
<?php
60
-
61
-
namespace App\Http\Controllers;
62
-
63
-
use Illuminate\Http\Request;
64
-
use App\Http\Controllers\Controller;
65
-
use Webfox\Xero\OauthCredentialManager;
66
-
67
-
class XeroController extends Controller
68
-
{
69
-
70
-
public function index(Request $request, OauthCredentialManager $xeroCredentials)
71
-
{
72
-
try {
73
-
// Check if we've got any stored credentials
74
-
if ($xeroCredentials->exists()) {
75
-
/*
76
-
* We have stored credentials so we can resolve the AccountingApi,
77
-
* If we were sure we already had some stored credentials then we could just resolve this through the controller
78
-
* But since we use this route for the initial authentication we cannot be sure!
In the event that a user denies access on the Xero Authorisation page, the package will throw a `OAuthException` from the [AuthorizationCallbackController](src/Controllers/AuthorizationCallbackController.php). This can be caught and acted upon however you prefer.
141
-
142
-
#### Laravel 11
143
-
144
-
To do this in Laravel 11, bind a custom exception renderer in `bootstrap/app.php`:
Credentials are stored in a JSON file using the default disk on the Laravel Filesystem, with visibility set to private. This allows credential sharing across multiple servers using a shared disk such as S3, regardless of which server conducted the OAuth flow.
181
-
182
-
To use a different disk, change the `xero.credential_disk` config item to another disk defined in `config/filesystem.php`.
183
-
184
-
You can switch out the credential store (e.g. for your own `UserStore` if you wanted to store
185
-
the credentials against your user) in one of two ways:
186
-
187
-
1. If it's a simple store and Laravel can automatically resolve your bindings, simply change the `xero.credential_store` config
188
-
key to point to your new implementation.
189
-
2. If it requires more advanced logic (e.g. using the current user to retrieve the credentials) then you can rebind this
Credentials are stored in a JSON file using the default disk on the Laravel Filesystem, with visibility set to private. This allows credential sharing across multiple servers using a shared disk such as S3, regardless of which server conducted the OAuth flow.
4
+
5
+
To use a different disk, change the `xero.credential_disk` config item to another disk defined in `config/filesystem.php`.
6
+
7
+
You can switch out the credential store (e.g. for your own `UserStore` if you wanted to store
8
+
the credentials against your user) in one of two ways:
9
+
10
+
1. If it's a simple store and Laravel can automatically resolve your bindings, simply change the `xero.credential_store` config
11
+
key to point to your new implementation.
12
+
2. If it requires more advanced logic (e.g. using the current user to retrieve the credentials) then you can rebind this
0 commit comments