From fb6ffaa9d929ca21cd1e5cc7b5d16959867c6b54 Mon Sep 17 00:00:00 2001 From: jitendra Date: Tue, 9 Apr 2019 16:27:33 +0530 Subject: [PATCH] JWT implemented for customer api authorization --- composer.json | 3 ++- config/auth.php | 2 +- config/debugbar.php | 2 +- config/tinker.php | 15 ------------ config/translatable.php | 4 ++-- .../Webkul/Customer/src/Models/Customer.php | 23 ++++++++++++++++++- .../views/vendor/mail/html/message.blade.php | 2 +- .../vendor/mail/markdown/message.blade.php | 2 +- .../vendor/notifications/email.blade.php | 2 +- 9 files changed, 31 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index aace66d41..48c2fa1f2 100755 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "maatwebsite/excel": "3.1.x-dev", "nwidart/laravel-modules": "^3.2", "prettus/l5-repository": "^2.6", - "propaganistas/laravel-intl": "^2.0" + "propaganistas/laravel-intl": "^2.0", + "tymon/jwt-auth": "dev-develop" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.1", diff --git a/config/auth.php b/config/auth.php index caa89e114..6b8c92e4b 100755 --- a/config/auth.php +++ b/config/auth.php @@ -13,7 +13,7 @@ return [ ], 'api' => [ - 'driver' => 'token', + 'driver' => 'jwt', 'provider' => 'customers', ], diff --git a/config/debugbar.php b/config/debugbar.php index c7c9ceee3..8350e1c8d 100755 --- a/config/debugbar.php +++ b/config/debugbar.php @@ -16,7 +16,7 @@ return [ 'enabled' => env('DEBUGBAR_ENABLED', null), 'except' => [ - 'telescope*' + // ], /* diff --git a/config/tinker.php b/config/tinker.php index 181f0fdbd..1341c1b03 100755 --- a/config/tinker.php +++ b/config/tinker.php @@ -2,21 +2,6 @@ return [ - /* - |-------------------------------------------------------------------------- - | Console Commands - |-------------------------------------------------------------------------- - | - | This option allows you to add additional Artisan commands that should - | be available within the Tinker environment. Once the command is in - | this array you may execute the command in Tinker using its name. - | - */ - - 'commands' => [ - // App\Console\Commands\ExampleCommand::class, - ], - /* |-------------------------------------------------------------------------- | Alias Blacklist diff --git a/config/translatable.php b/config/translatable.php index 17bf04aac..1ef910d3e 100755 --- a/config/translatable.php +++ b/config/translatable.php @@ -54,7 +54,7 @@ return [ | $useTranslationFallback when defined | */ - 'use_fallback' => true, + 'use_fallback' => false, /* |-------------------------------------------------------------------------- @@ -113,4 +113,4 @@ return [ | */ 'to_array_always_loads_translations' => true, -]; \ No newline at end of file +]; diff --git a/packages/Webkul/Customer/src/Models/Customer.php b/packages/Webkul/Customer/src/Models/Customer.php index 367101395..b49329a39 100755 --- a/packages/Webkul/Customer/src/Models/Customer.php +++ b/packages/Webkul/Customer/src/Models/Customer.php @@ -4,13 +4,14 @@ namespace Webkul\Customer\Models; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; +use Tymon\JWTAuth\Contracts\JWTSubject; use Webkul\Checkout\Models\CartProxy; use Webkul\Sales\Models\OrderProxy; use Webkul\Product\Models\ProductReviewProxy; use Webkul\Customer\Notifications\CustomerResetPassword; use Webkul\Customer\Contracts\Customer as CustomerContract; -class Customer extends Authenticatable implements CustomerContract +class Customer extends Authenticatable implements CustomerContract, JWTSubject { use Notifiable; @@ -103,4 +104,24 @@ class Customer extends Authenticatable implements CustomerContract public function all_orders() { return $this->hasMany(OrderProxy::modelClass(), 'customer_id'); } + + /** + * Get the identifier that will be stored in the subject claim of the JWT. + * + * @return mixed + */ + public function getJWTIdentifier() + { + return $this->getKey(); + } + + /** + * Return a key value array, containing any custom claims to be added to the JWT. + * + * @return array + */ + public function getJWTCustomClaims() + { + return []; + } } diff --git a/resources/views/vendor/mail/html/message.blade.php b/resources/views/vendor/mail/html/message.blade.php index 1ae9ed8f1..2ad23a66e 100755 --- a/resources/views/vendor/mail/html/message.blade.php +++ b/resources/views/vendor/mail/html/message.blade.php @@ -21,7 +21,7 @@ {{-- Footer --}} @slot('footer') @component('mail::footer') - © {{ date('Y') }} {{ config('app.name') }}. @lang('All rights reserved.') + © {{ date('Y') }} {{ config('app.name') }}. All rights reserved. @endcomponent @endslot @endcomponent diff --git a/resources/views/vendor/mail/markdown/message.blade.php b/resources/views/vendor/mail/markdown/message.blade.php index 1ae9ed8f1..b409c71cb 100755 --- a/resources/views/vendor/mail/markdown/message.blade.php +++ b/resources/views/vendor/mail/markdown/message.blade.php @@ -21,7 +21,7 @@ {{-- Footer --}} @slot('footer') @component('mail::footer') - © {{ date('Y') }} {{ config('app.name') }}. @lang('All rights reserved.') + © {{ date('Y') }} {{ config('app.name') }}. All rights reserved. @endcomponent @endslot @endcomponent diff --git a/resources/views/vendor/notifications/email.blade.php b/resources/views/vendor/notifications/email.blade.php index e2c68be68..fe3889532 100755 --- a/resources/views/vendor/notifications/email.blade.php +++ b/resources/views/vendor/notifications/email.blade.php @@ -56,7 +56,7 @@ 'into your web browser: [:actionURL](:actionURL)', [ 'actionText' => $actionText, - 'actionURL' => $actionUrl, + 'actionURL' => $actionUrl ] ) @endcomponent