From 2fddbe11e9b73678e3cda3cdc9fe37678ed693c1 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 27 May 2023 15:11:38 +0200 Subject: [PATCH] fix: fix socialite integration (monicahq/chandler#554) --- .../Web/ViewHelpers/JournalShowViewHelper.php | 2 +- .../Auth/AcceptInvitationController.php | 2 +- .../Auth/SocialiteCallbackController.php | 2 +- composer.lock | 23 +++++++++++++------ ..._06_065356_create_user_token_socialite.php | 2 +- routes/web.php | 2 +- .../Auth/SocialiteCallbackControllerTest.php | 4 ++-- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/Domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php b/app/Domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php index 4b43cccdbaa..4ae7b2a1235 100644 --- a/app/Domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php +++ b/app/Domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php @@ -82,7 +82,7 @@ public static function postsInYear(Journal $journal, int $year, User $user): Col 'excerpt' => $post->excerpt, 'written_at_day' => Str::upper(DateHelper::formatShortDay($post->written_at)), 'written_at_day_number' => DateHelper::formatDayNumber($post->written_at), - 'photo' => $post?->files?->first() ? [ + 'photo' => optional(optional($post)->files)->first() ? [ 'id' => $post->files->first()->id, 'url' => [ 'show' => 'https://ucarecdn.com/'.$post->files->first()->uuid.'/-/scale_crop/75x75/smart/-/format/auto/-/quality/smart_retina/', diff --git a/app/Http/Controllers/Auth/AcceptInvitationController.php b/app/Http/Controllers/Auth/AcceptInvitationController.php index 4230b550d8b..3ac67cec2de 100644 --- a/app/Http/Controllers/Auth/AcceptInvitationController.php +++ b/app/Http/Controllers/Auth/AcceptInvitationController.php @@ -50,7 +50,7 @@ public function store(Request $request) Auth::login($user); return response()->json([ - 'data' => route('vault.index'), + 'data' => route('home'), ], 200); } } diff --git a/app/Http/Controllers/Auth/SocialiteCallbackController.php b/app/Http/Controllers/Auth/SocialiteCallbackController.php index 99b2aa1fa2d..5f7b7270873 100644 --- a/app/Http/Controllers/Auth/SocialiteCallbackController.php +++ b/app/Http/Controllers/Auth/SocialiteCallbackController.php @@ -47,7 +47,7 @@ public function callback(Request $request, string $driver): RedirectResponse $this->checkForErrors($request, $driver); return $this->loginPipeline($request)->then(function (/*$request*/) { - return Redirect::intended(route('vault.index')); + return Redirect::intended(route('home')); }); } catch (ValidationException $e) { throw $e->redirectTo(Redirect::intended(route('home'))->getTargetUrl()); diff --git a/composer.lock b/composer.lock index 629acf91c3f..d35a1c02f0b 100644 --- a/composer.lock +++ b/composer.lock @@ -6795,21 +6795,21 @@ }, { "name": "socialiteproviders/twitter", - "version": "4.1.1", + "version": "4.1.2", "source": { "type": "git", "url": "https://github.com/SocialiteProviders/Twitter.git", - "reference": "e5edf2b6e3f37e64be6488111629ed5e41e645ad" + "reference": "54ddc36c1475bbdc111a89edee1468e3c9cf1229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/SocialiteProviders/Twitter/zipball/e5edf2b6e3f37e64be6488111629ed5e41e645ad", - "reference": "e5edf2b6e3f37e64be6488111629ed5e41e645ad", + "url": "https://api.github.com/repos/SocialiteProviders/Twitter/zipball/54ddc36c1475bbdc111a89edee1468e3c9cf1229", + "reference": "54ddc36c1475bbdc111a89edee1468e3c9cf1229", "shasum": "" }, "require": { "ext-json": "*", - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "socialiteproviders/manager": "~4.0" }, "type": "library", @@ -6829,10 +6829,19 @@ } ], "description": "Twitter OAuth1 Provider for Laravel Socialite", + "keywords": [ + "laravel", + "oauth", + "provider", + "socialite", + "twitter" + ], "support": { - "source": "https://github.com/SocialiteProviders/Twitter/tree/4.1.1" + "docs": "https://socialiteproviders.com/twitter", + "issues": "https://github.com/socialiteproviders/providers/issues", + "source": "https://github.com/socialiteproviders/providers" }, - "time": "2021-01-29T05:41:11+00:00" + "time": "2023-05-25T23:12:53+00:00" }, { "name": "spatie/data-transfer-object", diff --git a/database/migrations/2021_07_06_065356_create_user_token_socialite.php b/database/migrations/2021_07_06_065356_create_user_token_socialite.php index b9dbb06eea5..6305231fd74 100644 --- a/database/migrations/2021_07_06_065356_create_user_token_socialite.php +++ b/database/migrations/2021_07_06_065356_create_user_token_socialite.php @@ -19,7 +19,7 @@ public function up() $table->string('driver', 50); $table->char('format', 6); $table->string('email', 1024)->nullable(); - $table->string('token', 2048); + $table->string('token', 4096); $table->string('token_secret', 2048)->nullable(); $table->string('refresh_token', 2048)->nullable(); $table->unsignedBigInteger('expires_in')->nullable(); diff --git a/routes/web.php b/routes/web.php index f88a966e56b..ca8a8ffa2e0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -151,7 +151,7 @@ return Redirect::route('login'); } if (($vaults = Auth::user()->vaults)->count() === 1) { - return Redirect::route('vault.show', $vaults->first()); + return Redirect::intended(route('vault.show', $vaults->first())); } return Redirect::intended(RouteServiceProvider::HOME); diff --git a/tests/Feature/Controllers/Auth/SocialiteCallbackControllerTest.php b/tests/Feature/Controllers/Auth/SocialiteCallbackControllerTest.php index 8f37dd21522..7332f7bfd44 100644 --- a/tests/Feature/Controllers/Auth/SocialiteCallbackControllerTest.php +++ b/tests/Feature/Controllers/Auth/SocialiteCallbackControllerTest.php @@ -92,7 +92,7 @@ public function it_get_user_created(): void $response = $this->get('/auth/test/callback?code=thecode&state=state'); $response->assertStatus(302); - $response->assertRedirect(config('app.url').'/vaults'); + $response->assertRedirect(config('app.url')); $mock->assertResponses(); @@ -123,7 +123,7 @@ public function it_associate_token_to_logged_user(): void $response = $this->get('/auth/test/callback?code=thecode&state=state'); $response->assertStatus(302); - $response->assertRedirect(config('app.url').'/vaults'); + $response->assertRedirect(config('app.url')); $mock->assertResponses();