4743 use auth google apis callback url instead of messaging provider gmail callback url (#4838)
Closes #4743
This commit is contained in:
@ -69,8 +69,7 @@ import TabItem from '@theme/TabItem';
|
|||||||
<OptionTable options={[
|
<OptionTable options={[
|
||||||
['MESSAGING_PROVIDER_GMAIL_ENABLED', 'false', 'Enable Gmail API connection'],
|
['MESSAGING_PROVIDER_GMAIL_ENABLED', 'false', 'Enable Gmail API connection'],
|
||||||
['CALENDAR_PROVIDER_GMAIL_ENABLED', 'false', 'Enable Google Calendar API connection'],
|
['CALENDAR_PROVIDER_GMAIL_ENABLED', 'false', 'Enable Google Calendar API connection'],
|
||||||
['MESSAGING_PROVIDER_GMAIL_CALLBACK_URL', '', 'Gmail auth callback'],
|
['AUTH_GOOGLE_APIS_CALLBACK_URL', '', 'Google APIs auth callback'],
|
||||||
['AUTH_GOOGLE_APIS_CALLBACK_URL', '', 'Google API auth callback'],
|
|
||||||
['AUTH_GOOGLE_ENABLED', 'false', 'Enable Goole SSO login'],
|
['AUTH_GOOGLE_ENABLED', 'false', 'Enable Goole SSO login'],
|
||||||
['AUTH_GOOGLE_CLIENT_ID', '', 'Google client ID'],
|
['AUTH_GOOGLE_CLIENT_ID', '', 'Google client ID'],
|
||||||
['AUTH_GOOGLE_CLIENT_SECRET', '', 'Google client secret'],
|
['AUTH_GOOGLE_CLIENT_SECRET', '', 'Google client secret'],
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export const useTriggerGoogleApisOAuth = () => {
|
|||||||
const token =
|
const token =
|
||||||
transientToken.data?.generateTransientToken.transientToken.token;
|
transientToken.data?.generateTransientToken.transientToken.token;
|
||||||
|
|
||||||
window.location.href = `${authServerUrl}/auth/google-gmail?transientToken=${token}`;
|
window.location.href = `${authServerUrl}/auth/google-apis?transientToken=${token}`;
|
||||||
}, [generateTransientToken]);
|
}, [generateTransientToken]);
|
||||||
|
|
||||||
return { triggerGoogleApisOAuth };
|
return { triggerGoogleApisOAuth };
|
||||||
|
|||||||
@ -30,7 +30,6 @@ SIGN_IN_PREFILLED=true
|
|||||||
# AUTH_GOOGLE_CLIENT_ID=replace_me_with_google_client_id
|
# AUTH_GOOGLE_CLIENT_ID=replace_me_with_google_client_id
|
||||||
# AUTH_GOOGLE_CLIENT_SECRET=replace_me_with_google_client_secret
|
# AUTH_GOOGLE_CLIENT_SECRET=replace_me_with_google_client_secret
|
||||||
# AUTH_GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/redirect
|
# AUTH_GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/redirect
|
||||||
# MESSAGING_PROVIDER_GMAIL_CALLBACK_URL=http://localhost:3000/auth/google-gmail/get-access-token
|
|
||||||
# AUTH_GOOGLE_APIS_CALLBACK_URL=http://localhost:3000/auth/google-apis/get-access-token
|
# AUTH_GOOGLE_APIS_CALLBACK_URL=http://localhost:3000/auth/google-apis/get-access-token
|
||||||
# STORAGE_TYPE=local
|
# STORAGE_TYPE=local
|
||||||
# STORAGE_LOCAL_PATH=.local-storage
|
# STORAGE_LOCAL_PATH=.local-storage
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import { TokenService } from 'src/engine/core-modules/auth/services/token.servic
|
|||||||
import { GoogleAPIsService } from 'src/engine/core-modules/auth/services/google-apis.service';
|
import { GoogleAPIsService } from 'src/engine/core-modules/auth/services/google-apis.service';
|
||||||
import { UserWorkspaceModule } from 'src/engine/core-modules/user-workspace/user-workspace.module';
|
import { UserWorkspaceModule } from 'src/engine/core-modules/user-workspace/user-workspace.module';
|
||||||
import { SignUpService } from 'src/engine/core-modules/auth/services/sign-up.service';
|
import { SignUpService } from 'src/engine/core-modules/auth/services/sign-up.service';
|
||||||
import { GoogleGmailAuthController } from 'src/engine/core-modules/auth/controllers/google-gmail-auth.controller';
|
|
||||||
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||||
import { FileUploadModule } from 'src/engine/core-modules/file/file-upload/file-upload.module';
|
import { FileUploadModule } from 'src/engine/core-modules/file/file-upload/file-upload.module';
|
||||||
import { AppTokenService } from 'src/engine/core-modules/app-token/services/app-token.service';
|
import { AppTokenService } from 'src/engine/core-modules/app-token/services/app-token.service';
|
||||||
@ -58,7 +57,6 @@ const jwtModule = JwtModule.registerAsync({
|
|||||||
controllers: [
|
controllers: [
|
||||||
GoogleAuthController,
|
GoogleAuthController,
|
||||||
GoogleAPIsAuthController,
|
GoogleAPIsAuthController,
|
||||||
GoogleGmailAuthController,
|
|
||||||
VerifyAuthController,
|
VerifyAuthController,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
|
|
||||||
|
|
||||||
import { Response } from 'express';
|
|
||||||
|
|
||||||
import { GoogleAPIsOauthGuard } from 'src/engine/core-modules/auth/guards/google-apis-oauth.guard';
|
|
||||||
import { GoogleAPIsProviderEnabledGuard } from 'src/engine/core-modules/auth/guards/google-apis-provider-enabled.guard';
|
|
||||||
import { GoogleAPIsService } from 'src/engine/core-modules/auth/services/google-apis.service';
|
|
||||||
import { TokenService } from 'src/engine/core-modules/auth/services/token.service';
|
|
||||||
import { GoogleAPIsRequest } from 'src/engine/core-modules/auth/strategies/google-apis.auth.strategy';
|
|
||||||
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
|
|
||||||
|
|
||||||
@Controller('auth/google-gmail')
|
|
||||||
export class GoogleGmailAuthController {
|
|
||||||
constructor(
|
|
||||||
private readonly googleAPIsService: GoogleAPIsService,
|
|
||||||
private readonly tokenService: TokenService,
|
|
||||||
private readonly environmentService: EnvironmentService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
@UseGuards(GoogleAPIsProviderEnabledGuard, GoogleAPIsOauthGuard)
|
|
||||||
async googleAuth() {
|
|
||||||
// As this method is protected by Google Auth guard, it will trigger Google SSO flow
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('get-access-token')
|
|
||||||
@UseGuards(GoogleAPIsProviderEnabledGuard, GoogleAPIsOauthGuard)
|
|
||||||
async googleAuthGetAccessToken(
|
|
||||||
@Req() req: GoogleAPIsRequest,
|
|
||||||
@Res() res: Response,
|
|
||||||
) {
|
|
||||||
const { user } = req;
|
|
||||||
|
|
||||||
const { email, accessToken, refreshToken, transientToken } = user;
|
|
||||||
|
|
||||||
const { workspaceMemberId, workspaceId } =
|
|
||||||
await this.tokenService.verifyTransientToken(transientToken);
|
|
||||||
|
|
||||||
const demoWorkspaceIds = this.environmentService.get('DEMO_WORKSPACE_IDS');
|
|
||||||
|
|
||||||
if (demoWorkspaceIds.includes(workspaceId)) {
|
|
||||||
throw new Error('Cannot connect Gmail account to demo workspace');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!workspaceId) {
|
|
||||||
throw new Error('Workspace not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.googleAPIsService.saveOrUpdateConnectedAccount({
|
|
||||||
handle: email,
|
|
||||||
workspaceMemberId: workspaceMemberId,
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
accessToken,
|
|
||||||
refreshToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.redirect(
|
|
||||||
`${this.environmentService.get('FRONT_BASE_URL')}/settings/accounts`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -41,9 +41,7 @@ export class GoogleAPIsStrategy extends PassportStrategy(
|
|||||||
super({
|
super({
|
||||||
clientID: environmentService.get('AUTH_GOOGLE_CLIENT_ID'),
|
clientID: environmentService.get('AUTH_GOOGLE_CLIENT_ID'),
|
||||||
clientSecret: environmentService.get('AUTH_GOOGLE_CLIENT_SECRET'),
|
clientSecret: environmentService.get('AUTH_GOOGLE_CLIENT_SECRET'),
|
||||||
callbackURL: environmentService.get('CALENDAR_PROVIDER_GOOGLE_ENABLED')
|
callbackURL: environmentService.get('AUTH_GOOGLE_APIS_CALLBACK_URL'),
|
||||||
? environmentService.get('AUTH_GOOGLE_APIS_CALLBACK_URL')
|
|
||||||
: environmentService.get('MESSAGING_PROVIDER_GMAIL_CALLBACK_URL'),
|
|
||||||
scope,
|
scope,
|
||||||
passReqToCallback: true,
|
passReqToCallback: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -272,8 +272,6 @@ export class EnvironmentVariables {
|
|||||||
@CastToBoolean()
|
@CastToBoolean()
|
||||||
MESSAGING_PROVIDER_GMAIL_ENABLED: boolean = false;
|
MESSAGING_PROVIDER_GMAIL_ENABLED: boolean = false;
|
||||||
|
|
||||||
MESSAGING_PROVIDER_GMAIL_CALLBACK_URL: string;
|
|
||||||
|
|
||||||
MESSAGE_QUEUE_TYPE: string = MessageQueueDriverType.Sync;
|
MESSAGE_QUEUE_TYPE: string = MessageQueueDriverType.Sync;
|
||||||
|
|
||||||
EMAIL_FROM_ADDRESS: string = 'noreply@yourdomain.com';
|
EMAIL_FROM_ADDRESS: string = 'noreply@yourdomain.com';
|
||||||
|
|||||||
Reference in New Issue
Block a user