From 0be49021850ef2bf8597985beb684b3f7bcd2db0 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 2 Aug 2024 10:39:10 +0330 Subject: [PATCH 1/9] support laravel passport --- src/Console/InstallCommand.php | 6 ++ src/Console/InstallsApiStack.php | 21 +++- .../views/auth/oauth/authorize.blade.php | 53 ++++++++++ .../js/Pages/Auth/OAuth/Authorize.tsx | 96 +++++++++++++++++++ .../js/Pages/Auth/OAuth/Authorize.jsx | 86 +++++++++++++++++ .../js/Pages/Auth/OAuth/Authorize.vue | 75 +++++++++++++++ .../js/Pages/Auth/OAuth/Authorize.vue | 75 +++++++++++++++ 7 files changed, 408 insertions(+), 4 deletions(-) create mode 100644 stubs/default/resources/views/auth/oauth/authorize.blade.php create mode 100644 stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx create mode 100644 stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx create mode 100644 stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue create mode 100644 stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 6c9fc02b7..a1a682d09 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -34,6 +34,7 @@ class InstallCommand extends Command implements PromptsForMissingInput {--pest : Indicate that Pest should be installed} {--ssr : Indicates if Inertia SSR support should be installed} {--typescript : Indicates if TypeScript is preferred for the Inertia stack} + {--oauth : Indicates that OAuth support via Laravel Passport should be installed for the API stack} {--composer=global : Absolute path to the Composer binary which should be used to install packages}'; /** @@ -386,6 +387,11 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp label: 'Would you like dark mode support?', default: false )); + } else if ($stack === 'api') { + $input->setOption('oauth', confirm( + label: 'Would you like OAuth support via Laravel Passport?', + default: false + )); } $input->setOption('pest', select( diff --git a/src/Console/InstallsApiStack.php b/src/Console/InstallsApiStack.php index 5834e1f99..1509747fb 100644 --- a/src/Console/InstallsApiStack.php +++ b/src/Console/InstallsApiStack.php @@ -13,7 +13,9 @@ trait InstallsApiStack */ protected function installApiStack() { - $this->runCommands(['php artisan install:api']); + $this->runCommands([ + $this->option('oauth') ? 'php artisan install:api --passport' : 'php artisan install:api', + ]); $files = new Filesystem; @@ -28,9 +30,15 @@ protected function installApiStack() 'verified' => '\App\Http\Middleware\EnsureEmailIsVerified::class', ]); - $this->installMiddleware([ - '\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class', - ], 'api', 'prepend'); + if ($this->option('oauth')) { + $this->installMiddleware([ + '\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class', + ], 'web', 'append'); + } else { + $this->installMiddleware([ + '\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class', + ], 'api', 'prepend'); + } // Requests... $files->ensureDirectoryExists(app_path('Http/Requests/Auth')); @@ -44,6 +52,11 @@ protected function installApiStack() copy(__DIR__.'/../../stubs/api/routes/web.php', base_path('routes/web.php')); copy(__DIR__.'/../../stubs/api/routes/auth.php', base_path('routes/auth.php')); + // OAuth... + if ($this->option('oauth')) { + $this->replaceInFile('auth:sanctum', 'auth:api', base_path('routes/api.php')); + } + // Configuration... $files->copyDirectory(__DIR__.'/../../stubs/api/config', config_path()); diff --git a/stubs/default/resources/views/auth/oauth/authorize.blade.php b/stubs/default/resources/views/auth/oauth/authorize.blade.php new file mode 100644 index 000000000..07ee1513b --- /dev/null +++ b/stubs/default/resources/views/auth/oauth/authorize.blade.php @@ -0,0 +1,53 @@ + +
+

{{ $user->name }}

+

{{ $user->email }}

+
+ +
+ {{ __(':client is requesting permission to access your account.', ['client' => $client->name]) }} +
+ + @if (count($scopes) > 0) +
+

{{ __('This application will be able to:') }}

+ +
    + @foreach ($scopes as $scope) +
  • {{ $scope->description }}
  • + @endforeach +
+
+ @endif + +
+
+ @csrf + + + + + + + {{ __('Authorize') }} + +
+ +
+ @csrf + @method('DELETE') + + + + + + + {{ __('Decline') }} + +
+ + + {{ __('Log into another account') }} + +
+
diff --git a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx new file mode 100644 index 000000000..991356d0e --- /dev/null +++ b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx @@ -0,0 +1,96 @@ +import { FormEventHandler } from 'react'; +import GuestLayout from '@/Layouts/GuestLayout'; +import PrimaryButton from '@/Components/PrimaryButton'; +import SecondaryButton from '@/Components/SecondaryButton'; +import { Head, Link, useForm } from '@inertiajs/react'; + +export default function Authorize({ + userName, + userEmail, + clientId, + clientName, + scopes, + state, + authToken, + promptLoginUrl, +}: { + userName: string, + userEmail: string, + clientId: string, + clientName: string, + scopes: { description: string }[], + state: string, + authToken: string, + promptLoginUrl: string, +}) { + const { post, processing, transform } = useForm({ + state: state, + client_id: clientId, + auth_token: authToken, + }); + + const approve: FormEventHandler = (e) => { + e.preventDefault(); + + post(route('passport.authorizations.approve')); + }; + + const deny: FormEventHandler = (e) => { + e.preventDefault(); + + transform((data) => ({ + ...data, + _method: 'delete', + })); + + post(route('passport.authorizations.deny')); + }; + + return ( + + + +
+

+ {userName} +

+

{userEmail}

+
+ +
+ {clientName} is requesting permission to access your account. +
+ + {scopes.length > 0 && ( +
+

This application will be able to:

+ +
    + {scopes.map((scope) => ( +
  • {scope.description}
  • + ))} +
+
+ )} + +
+
+ Authorize +
+ +
+ + Decline + +
+ + + Log into another account + +
+
+ ); +} diff --git a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx new file mode 100644 index 000000000..945245f74 --- /dev/null +++ b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx @@ -0,0 +1,86 @@ +import GuestLayout from '@/Layouts/GuestLayout'; +import PrimaryButton from '@/Components/PrimaryButton'; +import SecondaryButton from '@/Components/SecondaryButton'; +import { Head, Link, useForm } from '@inertiajs/react'; + +export default function Authorize({ + userName, + userEmail, + clientId, + clientName, + scopes, + state, + authToken, + promptLoginUrl, +}) { + const { post, processing, transform } = useForm({ + state: state, + client_id: clientId, + auth_token: authToken, + }); + + const approve = (e) => { + e.preventDefault(); + + post(route('passport.authorizations.approve')); + }; + + const deny = (e) => { + e.preventDefault(); + + transform((data) => ({ + ...data, + _method: 'delete', + })); + + post(route('passport.authorizations.deny')); + }; + + return ( + + + +
+

+ {userName} +

+

{userEmail}

+
+ +
+ {clientName} is requesting permission to access your account. +
+ + {scopes.length > 0 && ( +
+

This application will be able to:

+ +
    + {scopes.map((scope) => ( +
  • {scope.description}
  • + ))} +
+
+ )} + +
+
+ Authorize +
+ +
+ + Decline + +
+ + + Log into another account + +
+
+ ); +} diff --git a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue new file mode 100644 index 000000000..e252c6b7a --- /dev/null +++ b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -0,0 +1,75 @@ + + + diff --git a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue new file mode 100644 index 000000000..9e7e5c8b4 --- /dev/null +++ b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -0,0 +1,75 @@ + + + From b218e433cf66d8b02314ce8c2e148cf626951374 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 2 Aug 2024 10:49:12 +0330 Subject: [PATCH 2/9] formatting --- src/Console/InstallCommand.php | 2 +- .../resources/js/Pages/Auth/OAuth/Authorize.vue | 12 ++++++++---- .../resources/js/Pages/Auth/OAuth/Authorize.vue | 12 ++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index a1a682d09..f4ca86130 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -387,7 +387,7 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp label: 'Would you like dark mode support?', default: false )); - } else if ($stack === 'api') { + } elseif ($stack === 'api') { $input->setOption('oauth', confirm( label: 'Would you like OAuth support via Laravel Passport?', default: false diff --git a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue index e252c6b7a..d91e34108 100644 --- a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -25,7 +25,7 @@ const approve = () => { form.post(route('passport.authorizations.approve')); }; const deny = () => { - form.transform(data => ({ + form.transform((data) => ({ ...data, _method: 'delete', })).post(route('passport.authorizations.deny')); @@ -37,7 +37,9 @@ const deny = () => {
-

{{ userName }}

+

+ {{ userName }} +

{{ userEmail }}

@@ -66,8 +68,10 @@ const deny = () => { - + Log into another account diff --git a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue index 9e7e5c8b4..e3d10f9b9 100644 --- a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -25,7 +25,7 @@ const approve = () => { form.post(route('passport.authorizations.approve')); }; const deny = () => { - form.transform(data => ({ + form.transform((data) => ({ ...data, _method: 'delete', })).post(route('passport.authorizations.deny')); @@ -37,7 +37,9 @@ const deny = () => {
-

{{ userName }}

+

+ {{ userName }} +

{{ userEmail }}

@@ -66,8 +68,10 @@ const deny = () => { - + Log into another account From 029d40be662382f4d905d1931cc79ca845d2edda Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 3 Aug 2024 10:12:16 +0330 Subject: [PATCH 3/9] wip --- src/Console/InstallCommand.php | 10 +++--- src/Console/InstallsBladeStack.php | 10 ++++++ src/Console/InstallsInertiaStacks.php | 22 ++++++++++-- .../app/Providers/AppServiceProvider.php | 25 +++++++++++++ .../app/Providers/AppServiceProvider.php | 35 +++++++++++++++++++ .../js/Pages/Auth/OAuth/Authorize.tsx | 20 +++++------ .../js/Pages/Auth/OAuth/Authorize.jsx | 14 ++++---- .../js/Pages/Auth/OAuth/Authorize.vue | 14 ++++---- .../js/Pages/Auth/OAuth/Authorize.vue | 14 ++++---- 9 files changed, 121 insertions(+), 43 deletions(-) create mode 100644 stubs/default/app/Providers/AppServiceProvider.php create mode 100644 stubs/inertia-common/app/Providers/AppServiceProvider.php diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index f4ca86130..948718fc0 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -387,11 +387,6 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp label: 'Would you like dark mode support?', default: false )); - } elseif ($stack === 'api') { - $input->setOption('oauth', confirm( - label: 'Would you like OAuth support via Laravel Passport?', - default: false - )); } $input->setOption('pest', select( @@ -399,6 +394,11 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp options: ['Pest', 'PHPUnit'], default: $this->isUsingPest() ? 'Pest' : 'PHPUnit', ) === 'Pest'); + + $input->setOption('oauth', confirm( + label: 'Would you like OAuth support via Laravel Passport?', + default: false + )); } /** diff --git a/src/Console/InstallsBladeStack.php b/src/Console/InstallsBladeStack.php index cf602d600..a33aaf59a 100644 --- a/src/Console/InstallsBladeStack.php +++ b/src/Console/InstallsBladeStack.php @@ -25,6 +25,16 @@ protected function installBladeStack() ] + $packages; }); + // Install Passport... + if ($this->option('oauth')) { + if (! $this->requireComposerPackages(['laravel/passport:^13.0'])) { + return 1; + } + + // Providers... + (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/default/app/Providers', app_path('Providers')); + } + // Controllers... (new Filesystem)->ensureDirectoryExists(app_path('Http/Controllers')); (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/default/app/Http/Controllers', app_path('Http/Controllers')); diff --git a/src/Console/InstallsInertiaStacks.php b/src/Console/InstallsInertiaStacks.php index aa259a334..543d240eb 100644 --- a/src/Console/InstallsInertiaStacks.php +++ b/src/Console/InstallsInertiaStacks.php @@ -15,7 +15,11 @@ trait InstallsInertiaStacks protected function installInertiaVueStack() { // Install Inertia... - if (! $this->requireComposerPackages(['inertiajs/inertia-laravel:^1.0', 'laravel/sanctum:^4.0', 'tightenco/ziggy:^2.0'])) { + if (! $this->requireComposerPackages([ + 'inertiajs/inertia-laravel:^1.0', + $this->option('oauth') ? 'laravel/passport:^13.0' : 'laravel/sanctum:^4.0', + 'tightenco/ziggy:^2.0', + ])) { return 1; } @@ -41,6 +45,11 @@ protected function installInertiaVueStack() }); } + // Providers... + if ($this->option('oauth')) { + (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/inertia-common/app/Providers', app_path('Providers')); + } + // Controllers... (new Filesystem)->ensureDirectoryExists(app_path('Http/Controllers')); (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/inertia-common/app/Http/Controllers', app_path('Http/Controllers')); @@ -183,7 +192,11 @@ protected function installInertiaVueSsrStack() protected function installInertiaReactStack() { // Install Inertia... - if (! $this->requireComposerPackages(['inertiajs/inertia-laravel:^1.0', 'laravel/sanctum:^4.0', 'tightenco/ziggy:^2.0'])) { + if (! $this->requireComposerPackages([ + 'inertiajs/inertia-laravel:^1.0', + $this->option('oauth') ? 'laravel/passport:^13.0' : 'laravel/sanctum:^4.0', + 'tightenco/ziggy:^2.0' + ])) { return 1; } @@ -213,6 +226,11 @@ protected function installInertiaReactStack() }); } + // Providers... + if ($this->option('oauth')) { + (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/inertia-common/app/Providers', app_path('Providers')); + } + // Controllers... (new Filesystem)->ensureDirectoryExists(app_path('Http/Controllers')); (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/inertia-common/app/Http/Controllers', app_path('Http/Controllers')); diff --git a/stubs/default/app/Providers/AppServiceProvider.php b/stubs/default/app/Providers/AppServiceProvider.php new file mode 100644 index 000000000..6a67b5b7f --- /dev/null +++ b/stubs/default/app/Providers/AppServiceProvider.php @@ -0,0 +1,25 @@ + $params['user'], + 'client' => $params['client'], + 'scopes' => $params['scopes'], + 'state' => $params['request']->state, + 'authToken' => $params['authToken'], + 'promptLoginUrl' => $params['request']->fullUrlWithQuery(['prompt' => 'login']), + ]); + }); + } +} diff --git a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx index 991356d0e..4c91fcf95 100644 --- a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx +++ b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx @@ -5,19 +5,15 @@ import SecondaryButton from '@/Components/SecondaryButton'; import { Head, Link, useForm } from '@inertiajs/react'; export default function Authorize({ - userName, - userEmail, - clientId, - clientName, + user, + client, scopes, state, authToken, promptLoginUrl, }: { - userName: string, - userEmail: string, - clientId: string, - clientName: string, + user: { name: string, email: string }, + client: { id: string, name: string }, scopes: { description: string }[], state: string, authToken: string, @@ -25,7 +21,7 @@ export default function Authorize({ }) { const { post, processing, transform } = useForm({ state: state, - client_id: clientId, + client_id: client.id, auth_token: authToken, }); @@ -52,13 +48,13 @@ export default function Authorize({

- {userName} + {user.name}

-

{userEmail}

+

{user.email}

- {clientName} is requesting permission to access your account. + {client.name} is requesting permission to access your account.
{scopes.length > 0 && ( diff --git a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx index 945245f74..4c340eee2 100644 --- a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx +++ b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx @@ -4,10 +4,8 @@ import SecondaryButton from '@/Components/SecondaryButton'; import { Head, Link, useForm } from '@inertiajs/react'; export default function Authorize({ - userName, - userEmail, - clientId, - clientName, + user, + client, scopes, state, authToken, @@ -15,7 +13,7 @@ export default function Authorize({ }) { const { post, processing, transform } = useForm({ state: state, - client_id: clientId, + client_id: client.id, auth_token: authToken, }); @@ -42,13 +40,13 @@ export default function Authorize({

- {userName} + {user.name}

-

{userEmail}

+

{user.email}

- {clientName} is requesting permission to access your account. + {client.name} is requesting permission to access your account.
{scopes.length > 0 && ( diff --git a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue index d91e34108..41cbb2fde 100644 --- a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -5,10 +5,8 @@ import SecondaryButton from '@/Components/SecondaryButton.vue'; import { Head, Link, useForm } from '@inertiajs/vue3'; const props = defineProps<{ - userName: string; - userEmail: string; - clientId: string; - clientName: string; + user: { name: string, email: string }; + client: { id: string, name: string }; scopes: { description: string }[]; state: string; authToken: string; @@ -17,7 +15,7 @@ const props = defineProps<{ const form = useForm({ state: props.state, - client_id: props.clientId, + client_id: props.client.id, auth_token: props.authToken, }); @@ -38,13 +36,13 @@ const deny = () => {

- {{ userName }} + {{ user.name }}

-

{{ userEmail }}

+

{{ user.email }}

- {{ clientName }} is requesting permission to access your account. + {{ client.name }} is requesting permission to access your account.
diff --git a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue index e3d10f9b9..b4c8b4214 100644 --- a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -5,10 +5,8 @@ import SecondaryButton from '@/Components/SecondaryButton.vue'; import { Head, Link, useForm } from '@inertiajs/vue3'; const props = defineProps({ - userName: String, - userEmail: String, - clientId: String, - clientName: String, + user: Object, + client: Object, scopes: Array, state: String, authToken: String, @@ -17,7 +15,7 @@ const props = defineProps({ const form = useForm({ state: props.state, - client_id: props.clientId, + client_id: props.client.id, auth_token: props.authToken, }); @@ -38,13 +36,13 @@ const deny = () => {

- {{ userName }} + {{ user.name }}

-

{{ userEmail }}

+

{{ user.email }}

- {{ clientName }} is requesting permission to access your account. + {{ client.name }} is requesting permission to access your account.
From f7725110358a5dbbae89763472660bc469e90f51 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 3 Aug 2024 10:15:17 +0330 Subject: [PATCH 4/9] wip --- src/Console/InstallCommand.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 948718fc0..88baac91b 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -389,16 +389,18 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp )); } + if (in_array($stack, ['api', 'blade', 'react', 'vue'])) { + $input->setOption('oauth', confirm( + label: 'Would you like OAuth support via Laravel Passport?', + default: false + )); + } + $input->setOption('pest', select( label: 'Which testing framework do you prefer?', options: ['Pest', 'PHPUnit'], default: $this->isUsingPest() ? 'Pest' : 'PHPUnit', ) === 'Pest'); - - $input->setOption('oauth', confirm( - label: 'Would you like OAuth support via Laravel Passport?', - default: false - )); } /** From 79be7651912c94cbeca481a08ba40bd07854e09a Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 3 Aug 2024 10:18:30 +0330 Subject: [PATCH 5/9] wip --- src/Console/InstallsInertiaStacks.php | 2 +- .../resources/js/Pages/Auth/OAuth/Authorize.tsx | 4 ++-- .../resources/js/Pages/Auth/OAuth/Authorize.jsx | 9 +-------- .../resources/js/Pages/Auth/OAuth/Authorize.vue | 4 ++-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Console/InstallsInertiaStacks.php b/src/Console/InstallsInertiaStacks.php index 543d240eb..c78e3aa9f 100644 --- a/src/Console/InstallsInertiaStacks.php +++ b/src/Console/InstallsInertiaStacks.php @@ -195,7 +195,7 @@ protected function installInertiaReactStack() if (! $this->requireComposerPackages([ 'inertiajs/inertia-laravel:^1.0', $this->option('oauth') ? 'laravel/passport:^13.0' : 'laravel/sanctum:^4.0', - 'tightenco/ziggy:^2.0' + 'tightenco/ziggy:^2.0', ])) { return 1; } diff --git a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx index 4c91fcf95..b9d26fa71 100644 --- a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx +++ b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx @@ -12,8 +12,8 @@ export default function Authorize({ authToken, promptLoginUrl, }: { - user: { name: string, email: string }, - client: { id: string, name: string }, + user: { name: string; email: string }, + client: { id: string; name: string }, scopes: { description: string }[], state: string, authToken: string, diff --git a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx index 4c340eee2..0ab37bf57 100644 --- a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx +++ b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx @@ -3,14 +3,7 @@ import PrimaryButton from '@/Components/PrimaryButton'; import SecondaryButton from '@/Components/SecondaryButton'; import { Head, Link, useForm } from '@inertiajs/react'; -export default function Authorize({ - user, - client, - scopes, - state, - authToken, - promptLoginUrl, -}) { +export default function Authorize({ user, client, scopes, state, authToken, promptLoginUrl }) { const { post, processing, transform } = useForm({ state: state, client_id: client.id, diff --git a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue index 41cbb2fde..fc511af4a 100644 --- a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -5,8 +5,8 @@ import SecondaryButton from '@/Components/SecondaryButton.vue'; import { Head, Link, useForm } from '@inertiajs/vue3'; const props = defineProps<{ - user: { name: string, email: string }; - client: { id: string, name: string }; + user: { name: string; email: string }; + client: { id: string; name: string }; scopes: { description: string }[]; state: string; authToken: string; From 199774a9844a4fc2e786605bb80819e3b8d51ada Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Thu, 15 Aug 2024 01:17:49 +0330 Subject: [PATCH 6/9] wip --- .../inertia-common/app/Providers/AppServiceProvider.php | 9 +-------- .../resources/js/Pages/Auth/OAuth/Authorize.tsx | 8 ++------ .../resources/js/Pages/Auth/OAuth/Authorize.jsx | 6 +++--- .../resources/js/Pages/Auth/OAuth/Authorize.vue | 6 ++---- .../resources/js/Pages/Auth/OAuth/Authorize.vue | 6 ++---- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/stubs/inertia-common/app/Providers/AppServiceProvider.php b/stubs/inertia-common/app/Providers/AppServiceProvider.php index 538a6a3fb..591596272 100644 --- a/stubs/inertia-common/app/Providers/AppServiceProvider.php +++ b/stubs/inertia-common/app/Providers/AppServiceProvider.php @@ -22,14 +22,7 @@ public function register(): void public function boot(): void { Passport::authorizationView(function ($params) { - return Inertia::render('Auth/OAuth/Authorize', [ - 'user' => $params['user'], - 'client' => $params['client'], - 'scopes' => $params['scopes'], - 'state' => $params['request']->state, - 'authToken' => $params['authToken'], - 'promptLoginUrl' => $params['request']->fullUrlWithQuery(['prompt' => 'login']), - ]); + return Inertia::render('Auth/OAuth/Authorize', $params); }); } } diff --git a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx index b9d26fa71..9f54eedf0 100644 --- a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx +++ b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx @@ -8,19 +8,15 @@ export default function Authorize({ user, client, scopes, - state, authToken, - promptLoginUrl, }: { user: { name: string; email: string }, client: { id: string; name: string }, scopes: { description: string }[], - state: string, authToken: string, - promptLoginUrl: string, }) { const { post, processing, transform } = useForm({ - state: state, + state: route().params.state, client_id: client.id, auth_token: authToken, }); @@ -81,7 +77,7 @@ export default function Authorize({ Log into another account diff --git a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx index 0ab37bf57..2c3cd535d 100644 --- a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx +++ b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx @@ -3,9 +3,9 @@ import PrimaryButton from '@/Components/PrimaryButton'; import SecondaryButton from '@/Components/SecondaryButton'; import { Head, Link, useForm } from '@inertiajs/react'; -export default function Authorize({ user, client, scopes, state, authToken, promptLoginUrl }) { +export default function Authorize({ user, client, scopes, authToken }) { const { post, processing, transform } = useForm({ - state: state, + state: route().params.state, client_id: client.id, auth_token: authToken, }); @@ -66,7 +66,7 @@ export default function Authorize({ user, client, scopes, state, authToken, prom Log into another account diff --git a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue index fc511af4a..3319e8a76 100644 --- a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -8,13 +8,11 @@ const props = defineProps<{ user: { name: string; email: string }; client: { id: string; name: string }; scopes: { description: string }[]; - state: string; authToken: string; - promptLoginUrl: string; }>(); const form = useForm({ - state: props.state, + state: route().params.state, client_id: props.client.id, auth_token: props.authToken, }); @@ -67,7 +65,7 @@ const deny = () => { Log into another account diff --git a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue index b4c8b4214..9632722a7 100644 --- a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -8,13 +8,11 @@ const props = defineProps({ user: Object, client: Object, scopes: Array, - state: String, authToken: String, - promptLoginUrl: String, }); const form = useForm({ - state: props.state, + state: route().params.state, client_id: props.client.id, auth_token: props.authToken, }); @@ -67,7 +65,7 @@ const deny = () => { Log into another account From 9dbceb0759bffcfdda3376ccce81b8ce65467abe Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Thu, 15 Aug 2024 01:30:24 +0330 Subject: [PATCH 7/9] wip --- .../resources/js/Pages/Auth/OAuth/Authorize.tsx | 2 +- stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx | 2 +- .../inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue | 2 +- stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx index 9f54eedf0..bc6996f3e 100644 --- a/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx +++ b/stubs/inertia-react-ts/resources/js/Pages/Auth/OAuth/Authorize.tsx @@ -77,7 +77,7 @@ export default function Authorize({ Log into another account diff --git a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx index 2c3cd535d..cee4b1ff2 100644 --- a/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx +++ b/stubs/inertia-react/resources/js/Pages/Auth/OAuth/Authorize.jsx @@ -66,7 +66,7 @@ export default function Authorize({ user, client, scopes, authToken }) { Log into another account diff --git a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue index 3319e8a76..e05388988 100644 --- a/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue-ts/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -65,7 +65,7 @@ const deny = () => { Log into another account diff --git a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue index 9632722a7..9abf5a5a5 100644 --- a/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue +++ b/stubs/inertia-vue/resources/js/Pages/Auth/OAuth/Authorize.vue @@ -65,7 +65,7 @@ const deny = () => { Log into another account From cca8c3fb47d5bfd065037ffcf1fcd91611e09a70 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 6 Sep 2024 18:47:46 +0330 Subject: [PATCH 8/9] fix tests --- stubs/inertia-common/app/Providers/AppServiceProvider.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stubs/inertia-common/app/Providers/AppServiceProvider.php b/stubs/inertia-common/app/Providers/AppServiceProvider.php index 6590e5cee..36cd57627 100644 --- a/stubs/inertia-common/app/Providers/AppServiceProvider.php +++ b/stubs/inertia-common/app/Providers/AppServiceProvider.php @@ -24,8 +24,10 @@ public function boot(): void { Vite::prefetch(concurrency: 3); - Passport::authorizationView(function ($params) { - return Inertia::render('Auth/OAuth/Authorize', $params); - }); + if (class_exists(Passport::class)) { + Passport::authorizationView(function ($params) { + return Inertia::render('Auth/OAuth/Authorize', $params); + }); + } } } From 70bb912174de8f135a550abd317166785ea73af1 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 6 Sep 2024 18:51:02 +0330 Subject: [PATCH 9/9] formatting --- stubs/inertia-common/app/Providers/AppServiceProvider.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stubs/inertia-common/app/Providers/AppServiceProvider.php b/stubs/inertia-common/app/Providers/AppServiceProvider.php index 36cd57627..6cc724db5 100644 --- a/stubs/inertia-common/app/Providers/AppServiceProvider.php +++ b/stubs/inertia-common/app/Providers/AppServiceProvider.php @@ -25,9 +25,7 @@ public function boot(): void Vite::prefetch(concurrency: 3); if (class_exists(Passport::class)) { - Passport::authorizationView(function ($params) { - return Inertia::render('Auth/OAuth/Authorize', $params); - }); + Passport::authorizationView(fn ($params) => Inertia::render('Auth/OAuth/Authorize', $params)); } } }