rename core-module environment to twenty-config (#11445)
closes https://github.com/twentyhq/core-team-issues/issues/759
This commit is contained in:
@ -3,15 +3,15 @@ import { Injectable } from '@nestjs/common';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
import { google } from 'googleapis';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleOAuth2ClientManagerService {
|
||||
constructor(private readonly environmentService: EnvironmentService) {}
|
||||
constructor(private readonly twentyConfigService: TwentyConfigService) {}
|
||||
|
||||
public async getOAuth2Client(refreshToken: string): Promise<OAuth2Client> {
|
||||
const gmailClientId = this.environmentService.get('AUTH_GOOGLE_CLIENT_ID');
|
||||
const gmailClientSecret = this.environmentService.get(
|
||||
const gmailClientId = this.twentyConfigService.get('AUTH_GOOGLE_CLIENT_ID');
|
||||
const gmailClientSecret = this.twentyConfigService.get(
|
||||
'AUTH_GOOGLE_CLIENT_SECRET',
|
||||
);
|
||||
|
||||
|
||||
@ -6,11 +6,11 @@ import {
|
||||
Client,
|
||||
} from '@microsoft/microsoft-graph-client';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
|
||||
@Injectable()
|
||||
export class MicrosoftOAuth2ClientManagerService {
|
||||
constructor(private readonly environmentService: EnvironmentService) {}
|
||||
constructor(private readonly twentyConfigService: TwentyConfigService) {}
|
||||
|
||||
public async getOAuth2Client(refreshToken: string): Promise<Client> {
|
||||
const authProvider: AuthProvider = async (
|
||||
@ -21,13 +21,13 @@ export class MicrosoftOAuth2ClientManagerService {
|
||||
|
||||
urlData.append(
|
||||
'client_id',
|
||||
this.environmentService.get('AUTH_MICROSOFT_CLIENT_ID'),
|
||||
this.twentyConfigService.get('AUTH_MICROSOFT_CLIENT_ID'),
|
||||
);
|
||||
urlData.append('scope', 'https://graph.microsoft.com/.default');
|
||||
urlData.append('refresh_token', refreshToken);
|
||||
urlData.append(
|
||||
'client_secret',
|
||||
this.environmentService.get('AUTH_MICROSOFT_CLIENT_SECRET'),
|
||||
this.twentyConfigService.get('AUTH_MICROSOFT_CLIENT_SECRET'),
|
||||
);
|
||||
urlData.append('grant_type', 'refresh_token');
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
|
||||
export type GoogleTokens = {
|
||||
accessToken: string;
|
||||
@ -18,14 +18,16 @@ interface GoogleRefreshTokenResponse {
|
||||
}
|
||||
@Injectable()
|
||||
export class GoogleAPIRefreshAccessTokenService {
|
||||
constructor(private readonly environmentService: EnvironmentService) {}
|
||||
constructor(private readonly twentyConfigService: TwentyConfigService) {}
|
||||
|
||||
async refreshAccessToken(refreshToken: string): Promise<GoogleTokens> {
|
||||
const response = await axios.post<GoogleRefreshTokenResponse>(
|
||||
'https://oauth2.googleapis.com/token',
|
||||
{
|
||||
client_id: this.environmentService.get('AUTH_GOOGLE_CLIENT_ID'),
|
||||
client_secret: this.environmentService.get('AUTH_GOOGLE_CLIENT_SECRET'),
|
||||
client_id: this.twentyConfigService.get('AUTH_GOOGLE_CLIENT_ID'),
|
||||
client_secret: this.twentyConfigService.get(
|
||||
'AUTH_GOOGLE_CLIENT_SECRET',
|
||||
),
|
||||
refresh_token: refreshToken,
|
||||
grant_type: 'refresh_token',
|
||||
},
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { EnvironmentModule } from 'src/engine/core-modules/environment/environment.module';
|
||||
import { TwentyConfigModule } from 'src/engine/core-modules/twenty-config/twenty-config.module';
|
||||
import { MicrosoftAPIRefreshAccessTokenService } from 'src/modules/connected-account/refresh-tokens-manager/drivers/microsoft/services/microsoft-api-refresh-tokens.service';
|
||||
|
||||
@Module({
|
||||
imports: [EnvironmentModule],
|
||||
imports: [TwentyConfigModule],
|
||||
providers: [MicrosoftAPIRefreshAccessTokenService],
|
||||
exports: [MicrosoftAPIRefreshAccessTokenService],
|
||||
})
|
||||
|
||||
@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
|
||||
export type MicrosoftTokens = {
|
||||
accessToken: string;
|
||||
@ -20,14 +20,14 @@ interface MicrosoftRefreshTokenResponse {
|
||||
}
|
||||
@Injectable()
|
||||
export class MicrosoftAPIRefreshAccessTokenService {
|
||||
constructor(private readonly environmentService: EnvironmentService) {}
|
||||
constructor(private readonly twentyConfigService: TwentyConfigService) {}
|
||||
|
||||
async refreshTokens(refreshToken: string): Promise<MicrosoftTokens> {
|
||||
const response = await axios.post<MicrosoftRefreshTokenResponse>(
|
||||
'https://login.microsoftonline.com/common/oauth2/v2.0/token',
|
||||
new URLSearchParams({
|
||||
client_id: this.environmentService.get('AUTH_MICROSOFT_CLIENT_ID'),
|
||||
client_secret: this.environmentService.get(
|
||||
client_id: this.twentyConfigService.get('AUTH_MICROSOFT_CLIENT_ID'),
|
||||
client_secret: this.twentyConfigService.get(
|
||||
'AUTH_MICROSOFT_CLIENT_SECRET',
|
||||
),
|
||||
refresh_token: refreshToken,
|
||||
|
||||
Reference in New Issue
Block a user