Skip to content

Commit

Permalink
Update for DB table names
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhall17 committed Sep 15, 2022
1 parent 4e3f86e commit 64a4d1d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

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

## 2.0.1 - 2022-09-15

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.

This fixes the issue by renewing the token if there is less than 1 minute of expiry on the token.

## 2.0.0 - 2022-03-31

Support PHP8.1 and Laravel 9

## 1.1.0 - 2020-09-08

- Initial Release with Laravel 8.0
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ There are Token Drivers for both File and Database.

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


### Database

If using DB you will need to publish migrations.
#### Config

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

``` bash
php artisan vendor:publish --provider="MacsiDigital\OAuth2\Providers\OAuth2ServiceProvider" --tag="integration-config"
```

#### Migrations

If using DB driver you will need to publish migrations.

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

The majority of the setup can be found in the config file
### Integration Configuration

The majority of the setup can be found in the config file, which needs to be copied and placed in the laravel config directory

``` php
return [
Expand All @@ -64,12 +77,14 @@ return [
'scope' => ['openid email profile offline_access accounting.settings accounting.transactions accounting.contacts accounting.journals.read accounting.reports.read accounting.attachments']
],
'tokenProcessor' => '\MacsiDigital\OAuth2\Support\AuthorisationProcessor',
'tokenModel' => '\MacsiDigital\OAuth2\Support\FileToken',
'tokenModel' => '\MacsiDigital\OAuth2\Support\Token\File',
'authorisedRedirect' => '',
'failedRedirect' => '',
];
```

(Todo: Create a command to automatically publish the config file)

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:-

``` php
Expand Down Expand Up @@ -171,9 +186,9 @@ composer test
## ToDo

- Tests
- SOme proper documentation
- Some proper documentation

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.
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.

## Changelog

Expand Down
5 changes: 5 additions & 0 deletions config/oauth2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'table_name' => 'integrations',
];
2 changes: 1 addition & 1 deletion config/sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
'tokenModel' => '\MacsiDigital\OAuth2\Support\FileToken',
'authorisedRedirect' => '',
'failedRedirect' => '',
];
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateIntegrationsTable extends Migration
*/
public function up()
{
Schema::create('integrations', function (Blueprint $table) {
Schema::create(config('oauth2.table_name'), function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('access_token');
Expand All @@ -31,6 +31,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('integrations');
Schema::dropIfExists(config('oauth2.table_name'));
}
}
5 changes: 5 additions & 0 deletions src/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ class Integration implements Model
protected $casts = [
'additional' => 'array',
];

public function getTable()
{
return config('oauth2.table_name', parent::getTable());

This comment has been minimized.

Copy link
@bittlerr

bittlerr May 12, 2023

@colinhall17 It seems that you haven't changed implements to extends this throws an error

}
}
6 changes: 5 additions & 1 deletion src/Providers/OAuth2ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public function boot()
$this->publishes([
__DIR__ . '/../../database/migrations' => database_path('migrations/'),
], 'integration-migrations');

$this->publishes([
__DIR__.'/../../config/oauth2.php' => config_path('oauth2.php'),
], 'integration-config');
}
}

Expand All @@ -25,7 +29,7 @@ public function boot()
public function register()
{
$this->app->bind('oauth2', 'MacsiDigital\OAuth2\Package');

// Register the main class to use with the facade
$this->app->bind('oauth2.connection', 'MacsiDigital\OAuth2\Contracts\Connection');

Expand Down

0 comments on commit 64a4d1d

Please sign in to comment.