Skip to content

Commit 64a4d1d

Browse files
committed
Update for DB table names
1 parent 4e3f86e commit 64a4d1d

File tree

7 files changed

+48
-9
lines changed

7 files changed

+48
-9
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to `laravel-oauth2-client` will be documented in this file
44

5+
## 2.0.1 - 2022-09-15
6+
7+
In some cases the token check and API call can run over 1 second apart which can cause issues if the token check is at the token expiry time, as the API call fails due to an expired token.
8+
9+
This fixes the issue by renewing the token if there is less than 1 minute of expiry on the token.
10+
11+
## 2.0.0 - 2022-03-31
12+
13+
Support PHP8.1 and Laravel 9
14+
515
## 1.1.0 - 2020-09-08
616

717
- Initial Release with Laravel 8.0

README.md

+20-5
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,20 @@ There are Token Drivers for both File and Database.
3838

3939
The file driver will save a file in storage/app/oauth2, which will keep the token details required to communicate with the OAuth2 Server.
4040

41+
4142
### Database
4243

43-
If using DB you will need to publish migrations.
44+
#### Config
45+
46+
If you want to use the DB driver and would like to customise teh table name then you can publish the config file and amend the table_name column
47+
48+
``` bash
49+
php artisan vendor:publish --provider="MacsiDigital\OAuth2\Providers\OAuth2ServiceProvider" --tag="integration-config"
50+
```
51+
52+
#### Migrations
53+
54+
If using DB driver you will need to publish migrations.
4455

4556
``` bash
4657
php artisan vendor:publish --provider="MacsiDigital\OAuth2\Providers\OAuth2ServiceProvider" --tag="integration-migrations"
@@ -52,7 +63,9 @@ Then you will need to run migrations
5263
php artisan migrate
5364
```
5465

55-
The majority of the setup can be found in the config file
66+
### Integration Configuration
67+
68+
The majority of the setup can be found in the config file, which needs to be copied and placed in the laravel config directory
5669

5770
``` php
5871
return [
@@ -64,12 +77,14 @@ return [
6477
'scope' => ['openid email profile offline_access accounting.settings accounting.transactions accounting.contacts accounting.journals.read accounting.reports.read accounting.attachments']
6578
],
6679
'tokenProcessor' => '\MacsiDigital\OAuth2\Support\AuthorisationProcessor',
67-
'tokenModel' => '\MacsiDigital\OAuth2\Support\FileToken',
80+
'tokenModel' => '\MacsiDigital\OAuth2\Support\Token\File',
6881
'authorisedRedirect' => '',
6982
'failedRedirect' => '',
7083
];
7184
```
7285

86+
(Todo: Create a command to automatically publish the config file)
87+
7388
As the primary focus of the library is in packages, this needs to be loaded into laravel with an integration name through a service provider. So for xero:-
7489

7590
``` php
@@ -171,9 +186,9 @@ composer test
171186
## ToDo
172187

173188
- Tests
174-
- SOme proper documentation
189+
- Some proper documentation
175190

176-
Basically we are just defining how we can authorise nad communicate with the API. For more details on what this means check the documentation for laravel-api-client.
191+
Basically we are just defining how we can authorise and communicate with the API. For more details on what this means check the documentation for laravel-api-client.
177192

178193
## Changelog
179194

config/oauth2.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'table_name' => 'integrations',
5+
];

config/sample.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
'tokenModel' => '\MacsiDigital\OAuth2\Support\FileToken',
1313
'authorisedRedirect' => '',
1414
'failedRedirect' => '',
15-
];
15+
];

database/migrations/2020_05_10_000000_create_integrations_table.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateIntegrationsTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('integrations', function (Blueprint $table) {
16+
Schema::create(config('oauth2.table_name'), function (Blueprint $table) {
1717
$table->id();
1818
$table->string('name');
1919
$table->string('access_token');
@@ -31,6 +31,6 @@ public function up()
3131
*/
3232
public function down()
3333
{
34-
Schema::dropIfExists('integrations');
34+
Schema::dropIfExists(config('oauth2.table_name'));
3535
}
3636
}

src/Integration.php

+5
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ class Integration implements Model
3131
protected $casts = [
3232
'additional' => 'array',
3333
];
34+
35+
public function getTable()
36+
{
37+
return config('oauth2.table_name', parent::getTable());
38+
}
3439
}

src/Providers/OAuth2ServiceProvider.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public function boot()
1414
$this->publishes([
1515
__DIR__ . '/../../database/migrations' => database_path('migrations/'),
1616
], 'integration-migrations');
17+
18+
$this->publishes([
19+
__DIR__.'/../../config/oauth2.php' => config_path('oauth2.php'),
20+
], 'integration-config');
1721
}
1822
}
1923

@@ -25,7 +29,7 @@ public function boot()
2529
public function register()
2630
{
2731
$this->app->bind('oauth2', 'MacsiDigital\OAuth2\Package');
28-
32+
2933
// Register the main class to use with the facade
3034
$this->app->bind('oauth2.connection', 'MacsiDigital\OAuth2\Contracts\Connection');
3135

0 commit comments

Comments
 (0)