Skip to content

Beautiful Open-Source Form Builder

Refactor OAuth integration and improve code structure

JhumanJ14ba8f5e5bfd
diff --git a/api/app/Http/Controllers/Auth/OAuthController.php b/api/app/Http/Controllers/Auth/OAuthController.php
index fc532a3f7..1c05edab4 100644
--- a/api/app/Http/Controllers/Auth/OAuthController.php
+++ b/api/app/Http/Controllers/Auth/OAuthController.php
@@ -6,7 +6,6 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\Auth\Traits\ManagesJWT;
use App\Http\Resources\OAuthProviderResource;
use App\Integrations\OAuth\Drivers\Contracts\WidgetOAuthDriver;
-use App\Integrations\OAuth\OAuthConnectionService;
use App\Integrations\OAuth\OAuthProviderService;
use App\Service\OAuth\OAuthUserService;
use App\Service\OAuth\OAuthProviderService as OAuthProviderServiceClass;
@@ -22,7 +21,6 @@ class OAuthController extends Controller
public const INTENT_INTEGRATION = 'integration';
public function __construct(
- private OAuthConnectionService $oauthConnectionService,
private OAuthUserService $oauthUserService,
private OAuthProviderServiceClass $oauthProviderService
) {
@@ -61,7 +59,7 @@ class OAuthController extends Controller
], now()->addMinutes(5));
}
- $url = $this->oauthConnectionService->getRedirectUrl($providerService, $scopes);
+ $url = $this->getRedirectUrl($providerService, $scopes);
return response()->json(['url' => $url]);
}
@@ -220,4 +218,15 @@ class OAuthController extends Controller
// Default to auth if no context found
return self::INTENT_AUTH;
}
+
+ private function getRedirectUrl(OAuthProviderService $provider, array $scopes = []): string
+ {
+ $driver = $provider->getDriver();
+
+ if (!empty($scopes)) {
+ $driver->setScopes($scopes);
+ }
+
+ return $driver->getRedirectUrl();
+ }
}
diff --git a/api/app/Integrations/OAuth/OAuthConnectionService.php b/api/app/Integrations/OAuth/OAuthConnectionService.php
deleted file mode 100644
index 167bd15cd..000000000
--- a/api/app/Integrations/OAuth/OAuthConnectionService.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-namespace App\Integrations\OAuth;
-
-use App\Integrations\OAuth\Contracts\OAuthCompletionStrategy;
-use Illuminate\Http\JsonResponse;
-
-class OAuthConnectionService
-{
- public function getRedirectUrl(OAuthProviderService $provider, array $scopes = []): string
- {
- $driver = $provider->getDriver();
-
- if (!empty($scopes)) {
- $driver->setScopes($scopes);
- }
-
- return $driver->getRedirectUrl();
- }
-
- public function handleCallback(OAuthProviderService $provider, OAuthCompletionStrategy $strategy): JsonResponse
- {
- try {
- $driverUser = $provider->getDriver()->getUser();
- return $strategy->execute($provider, $driverUser);
- } catch (\Exception $e) {
- report($e);
- return response()->json(['message' => 'Failed to authenticate with the provider. Please try again.'], 400);
- }
- }
-}
diff --git a/client/components/open/integrations/GoogleSheetsIntegration.vue b/client/components/open/integrations/GoogleSheetsIntegration.vue
index 34da0d570..40dad5749 100644
--- a/client/components/open/integrations/GoogleSheetsIntegration.vue
+++ b/client/components/open/integrations/GoogleSheetsIntegration.vue
@@ -61,7 +61,7 @@ const props = defineProps({
const oAuth = useOAuth()
const { data: providersData, isLoading } = oAuth.providers()
const providers = computed(() => (providersData.value || []).filter(provider => provider.provider == 'google'))
-const disableProviders = computed(() => (providersData.value || []).filter(provider => !provider.scopes.includes(oAuth.googleDrivePermission)).map((provider) => provider.id))
+const disableProviders = computed(() => (providersData.value || []).filter(provider => !provider.scopes.includes(oAuth.googleDrivePermissionFileScope)).map((provider) => provider.id))
const { openUserSettings } = useAppModals()
function connect () {
diff --git a/client/components/open/integrations/components/GoogleSheetsIntegrationActions.vue b/client/components/open/integrations/components/GoogleSheetsIntegrationActions.vue
index 69507358a..d7087a731 100644
--- a/client/components/open/integrations/components/GoogleSheetsIntegrationActions.vue
+++ b/client/components/open/integrations/components/GoogleSheetsIntegrationActions.vue
@@ -1,34 +1,32 @@
<template>
- <div class="flex flex-1 items-center">
+ <div class="flex flex-1 items-center gap-2">
<div
v-if="integration.provider"
- class="hidden md:block space-y-1"
+ class="hidden md:flex items-center"
>
<UBadge
:label="mentionAsText(integration.provider.email)"
color="neutral"
variant="subtle"
- size="xs"
+ size="sm"
class="max-w-[300px] truncate"
/>
</div>
<div
v-if="integration.data"
- class="ml-auto"
+ class="ml-auto flex items-center"
>
<UButton
:to="integration.data.url"
target="_blank"
- color="white"
+ color="neutral"
size="sm"
variant="outline"
- class="block"
icon="mdi:google-spreadsheet"
trailing-icon="heroicons:arrow-top-right-on-square-20-solid"
- >
- Open
- </UButton>
+ label="Open"
+ />
</div>
</div>
</template>
diff --git a/client/composables/query/useOAuth.js b/client/composables/query/useOAuth.js
index 7cca1a9c8..4a582c693 100644
--- a/client/composables/query/useOAuth.js
+++ b/client/composables/query/useOAuth.js
@@ -7,14 +7,8 @@ export function useOAuth() {
const alert = useAlert()
// Constants
- const googleDrivePermission = {
- scope: 'https://www.googleapis.com/auth/drive.file',
- access_type: 'offline',
- prompt: 'consent',
- response_type: 'code',
- approval_prompt: 'force'
- }
-
+ const googleDrivePermissionFileScope = 'https://www.googleapis.com/auth/drive.file'
+
// Service definitions
const services = computed(() => {
return [
@@ -265,7 +259,7 @@ export function useOAuth() {
return {
// Constants
- googleDrivePermission,
+ googleDrivePermissionFileScope,
// Service definitions
services,