Fix auth connection (#15869)

Better to do auth this way than in module
This commit is contained in:
Félix Malfait
2025-11-17 18:12:48 +01:00
committed by GitHub
parent 8d7ee47ec5
commit 19ca93b954
9 changed files with 58 additions and 39 deletions
@@ -1,5 +1,7 @@
import { Injectable } from '@nestjs/common';
import { google } from 'googleapis';
import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service';
import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
@@ -17,11 +19,12 @@ export class GoogleEmailAliasManagerService {
connectedAccount,
);
const people = oAuth2Client.people({
const peopleClient = google.people({
version: 'v1',
auth: oAuth2Client,
});
const emailsResponse = await people.people.get({
const emailsResponse = await peopleClient.people.get({
resourceName: 'people/me',
personFields: 'emailAddresses',
});
@@ -1,6 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { google, GoogleApis } from 'googleapis';
import { google, type Auth } from 'googleapis';
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
@@ -11,7 +11,9 @@ export class GoogleOAuth2ClientManagerService {
private readonly logger: Logger,
) {}
public async getOAuth2Client(refreshToken: string): Promise<GoogleApis> {
public async getOAuth2Client(
refreshToken: string,
): Promise<Auth.OAuth2Client> {
const gmailClientId = this.twentyConfigService.get('AUTH_GOOGLE_CLIENT_ID');
const gmailClientSecret = this.twentyConfigService.get(
'AUTH_GOOGLE_CLIENT_SECRET',
@@ -27,9 +29,7 @@ export class GoogleOAuth2ClientManagerService {
refresh_token: refreshToken,
});
google.options({ auth: oAuth2Client });
return google;
return oAuth2Client;
} catch (error) {
this.logger.error(
`Error in ${GoogleOAuth2ClientManagerService.name}`,
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { type Client } from '@microsoft/microsoft-graph-client';
import { GoogleApis } from 'googleapis';
import { type Auth } from 'googleapis';
import { GoogleOAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/drivers/google/google-oauth2-client-manager.service';
import { MicrosoftOAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/drivers/microsoft/microsoft-oauth2-client-manager.service';
@@ -19,7 +19,7 @@ export class OAuth2ClientManagerService {
ConnectedAccountWorkspaceEntity,
'provider' | 'refreshToken'
>,
): Promise<GoogleApis> {
): Promise<Auth.OAuth2Client> {
return this.googleOAuth2ClientManagerService.getOAuth2Client(
connectedAccount.refreshToken,
);