Skip to content

Commit 9aa36f5

Browse files
committed
Wip: store scopes in connected accounts
1 parent 6693f2c commit 9aa36f5

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const GOOGLE_APIS_OAUTH_SCOPES = [
2+
'email',
3+
'profile',
4+
'https://www.googleapis.com/auth/gmail.readonly',
5+
'https://www.googleapis.com/auth/gmail.send',
6+
'https://www.googleapis.com/auth/calendar.events',
7+
'https://www.googleapis.com/auth/profile.emails.read',
8+
];

packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
MessagingMessageListFetchJobData,
3636
} from 'src/modules/messaging/message-import-manager/jobs/messaging-message-list-fetch.job';
3737
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
38+
import { GOOGLE_APIS_OAUTH_SCOPES } from 'src/engine/core-modules/auth/constants/google-apis-oauth-scopes';
3839

3940
@Injectable()
4041
export class GoogleAPIsService {
@@ -106,6 +107,7 @@ export class GoogleAPIsService {
106107
accessToken: input.accessToken,
107108
refreshToken: input.refreshToken,
108109
accountOwnerId: workspaceMemberId,
110+
scopes: GOOGLE_APIS_OAUTH_SCOPES,
109111
},
110112
workspaceId,
111113
manager,

packages/twenty-server/src/engine/core-modules/auth/strategies/google-apis-oauth-common.auth.strategy.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PassportStrategy } from '@nestjs/passport';
44
import { Strategy } from 'passport-google-oauth20';
55

66
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
7+
import { GOOGLE_APIS_OAUTH_SCOPES } from 'src/engine/core-modules/auth/constants/google-apis-oauth-scopes';
78

89
export type GoogleAPIScopeConfig = {
910
isCalendarEnabled?: boolean;
@@ -19,20 +20,11 @@ export class GoogleAPIsOauthCommonStrategy extends PassportStrategy(
1920
environmentService: EnvironmentService,
2021
scopeConfig: GoogleAPIScopeConfig,
2122
) {
22-
const scopes = [
23-
'email',
24-
'profile',
25-
'https://www.googleapis.com/auth/gmail.readonly',
26-
'https://www.googleapis.com/auth/gmail.send',
27-
'https://www.googleapis.com/auth/calendar.events',
28-
'https://www.googleapis.com/auth/profile.emails.read',
29-
];
30-
3123
super({
3224
clientID: environmentService.get('AUTH_GOOGLE_CLIENT_ID'),
3325
clientSecret: environmentService.get('AUTH_GOOGLE_CLIENT_SECRET'),
3426
callbackURL: environmentService.get('AUTH_GOOGLE_APIS_CALLBACK_URL'),
35-
scope: scopes,
27+
scope: GOOGLE_APIS_OAUTH_SCOPES,
3628
passReqToCallback: true,
3729
});
3830
}

packages/twenty-server/src/modules/connected-account/repositories/connected-account.repository.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EntityManager } from 'typeorm';
44

55
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
66
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
7+
import { GOOGLE_APIS_OAUTH_SCOPES } from 'src/engine/core-modules/auth/constants/google-apis-oauth-scopes';
78

89
@Injectable()
910
export class ConnectedAccountRepository {
@@ -90,6 +91,7 @@ export class ConnectedAccountRepository {
9091
| 'accessToken'
9192
| 'refreshToken'
9293
| 'accountOwnerId'
94+
| 'scopes'
9395
>,
9496
workspaceId: string,
9597
transactionManager?: EntityManager,
@@ -123,8 +125,8 @@ export class ConnectedAccountRepository {
123125
this.workspaceDataSourceService.getSchemaName(workspaceId);
124126

125127
await this.workspaceDataSourceService.executeRawQuery(
126-
`UPDATE ${dataSourceSchema}."connectedAccount" SET "accessToken" = $1, "refreshToken" = $2, "authFailedAt" = NULL WHERE "id" = $3`,
127-
[accessToken, refreshToken, connectedAccountId],
128+
`UPDATE ${dataSourceSchema}."connectedAccount" SET "accessToken" = $1, "refreshToken" = $2, "authFailedAt" = NULL, "scopes" = $3 WHERE "id" = $4`,
129+
[accessToken, refreshToken, GOOGLE_APIS_OAUTH_SCOPES, connectedAccountId],
128130
workspaceId,
129131
transactionManager,
130132
);

0 commit comments

Comments
 (0)