diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fdd9eb..c5bf62a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 30fe6f7..ce748e5 100644 --- a/README.md +++ b/README.md @@ -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" @@ -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 [ @@ -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 @@ -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 diff --git a/config/oauth2.php b/config/oauth2.php new file mode 100644 index 0000000..b669903 --- /dev/null +++ b/config/oauth2.php @@ -0,0 +1,5 @@ + 'integrations', +]; diff --git a/config/sample.php b/config/sample.php index c87f219..4d47d72 100644 --- a/config/sample.php +++ b/config/sample.php @@ -12,4 +12,4 @@ 'tokenModel' => '\MacsiDigital\OAuth2\Support\FileToken', 'authorisedRedirect' => '', 'failedRedirect' => '', -]; \ No newline at end of file +]; diff --git a/database/migrations/2020_05_10_000000_create_integrations_table.php b/database/migrations/2020_05_10_000000_create_integrations_table.php index 77d29e9..ba3192c 100644 --- a/database/migrations/2020_05_10_000000_create_integrations_table.php +++ b/database/migrations/2020_05_10_000000_create_integrations_table.php @@ -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'); @@ -31,6 +31,6 @@ public function up() */ public function down() { - Schema::dropIfExists('integrations'); + Schema::dropIfExists(config('oauth2.table_name')); } } diff --git a/src/Integration.php b/src/Integration.php index 2e5aebc..7a015ab 100644 --- a/src/Integration.php +++ b/src/Integration.php @@ -31,4 +31,9 @@ class Integration implements Model protected $casts = [ 'additional' => 'array', ]; + + public function getTable() + { + return config('oauth2.table_name', parent::getTable()); + } } diff --git a/src/Providers/OAuth2ServiceProvider.php b/src/Providers/OAuth2ServiceProvider.php index e521c1b..30a11be 100644 --- a/src/Providers/OAuth2ServiceProvider.php +++ b/src/Providers/OAuth2ServiceProvider.php @@ -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'); } } @@ -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');