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
+56-5Lines changed: 56 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,25 +9,30 @@ Laravel.
9
9
## Installation
10
10
11
11
You can install this package via composer using the following command:
12
+
12
13
```
13
14
composer require webfox/laravel-xero-oauth2
14
15
```
15
16
16
17
The package will automatically register itself.
17
18
18
19
You should add your Xero keys to your `.env` file using the following keys:
20
+
19
21
```
20
22
XERO_CLIENT_ID=
21
23
XERO_CLIENT_SECRET=
22
24
```
23
25
24
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
+
25
28
```
26
29
https://{your-domain}/xero/auth/callback
27
30
```
31
+
28
32
*(The flow is xero/auth/callback performs the oAuth handshake and stores your token, then redirects you over to your success callback)*
@@ -42,12 +47,14 @@ You can see all available scopes on [the official Xero documentation](https://de
42
47
## Using the Package
43
48
44
49
This package registers two bindings into the service container you'll be interested in:
50
+
45
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.
46
52
When you first resolve this dependency if the stored credentials are expired it will automatically refresh the token.
47
-
*`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.
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.
48
54
This is also where we can get information about the authenticating user. See below for an example.
49
55
50
56
*app\Http\Controllers\XeroController.php*
57
+
51
58
```php
52
59
<?php
53
60
@@ -92,6 +99,7 @@ class XeroController extends Controller
92
99
```
93
100
94
101
*resources\views\xero.blade.php*
102
+
95
103
```
96
104
@extends('_layouts.main')
97
105
@@ -118,6 +126,7 @@ class XeroController extends Controller
118
126
```
119
127
120
128
*routes/web.php*
129
+
121
130
```php
122
131
/*
123
132
* We name this route xero.auth.success as by default the config looks for a route with this name to redirect back to
@@ -126,17 +135,58 @@ class XeroController extends Controller
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.
131
181
132
182
To use a different disk, change the `xero.credential_disk` config item to another disk defined in `config/filesystem.php`.
133
183
134
-
You can switch out the credential store (e.g. for your own `UserStore` if you wanted to store
184
+
You can switch out the credential store (e.g. for your own `UserStore` if you wanted to store
135
185
the credentials against your user) in one of two ways:
136
186
137
187
1. If it's a simple store and Laravel can automatically resolve your bindings, simply change the `xero.credential_store` config
138
188
key to point to your new implementation.
139
-
2. If it requires more advanced logic (e.g. using the current user to retrieve the credentials) then you can rebind this
189
+
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