Skip to content

Commit e5aae1d

Browse files
configure http proxy in config file
1 parent 1419bec commit e5aae1d

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

packages/apollo-collaboration-server/src/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const validationSchema = Joi.object({
108108
})
109109
.default(''),
110110
PLUGIN_URLS_FILE: Joi.string(),
111+
OAUTH_HTTP_PROXY: Joi.string(),
111112
})
112113
.xor('MONGODB_URI', 'MONGODB_URI_FILE')
113114
.oxor('GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_ID_FILE')

packages/apollo-collaboration-server/src/utils/strategies/google.strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface ConfigValues {
1515
GOOGLE_CLIENT_SECRET_FILE?: string
1616
URL: string
1717
PORT: number
18+
OAUTH_HTTP_PROXY?: string
1819
}
1920

2021
@Injectable()
@@ -65,17 +66,16 @@ export class GoogleStrategy extends PassportStrategy(Strategy) {
6566
})
6667

6768
// Apply proxy to OAuth2 instance
68-
const proxy = process.env.HTTPS_PROXY ?? process.env.HTTP_PROXY
69+
const proxy = configService.get('OAUTH_HTTP_PROXY', { infer: true })
6970
if (proxy) {
7071
const agent = new HttpsProxyAgent(proxy)
7172

7273
// Access the internal OAuth2 instance and set the agent
7374
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
7475
const oauth2 = (this as any)._oauth2
7576
if (oauth2) {
76-
// https://github.com/ciaranj/node-oauth/blob/master/lib/oauth2.js#L20
7777
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
78-
oauth2._agent = agent
78+
oauth2.setAgent = agent
7979
this.logger.debug(`GoogleStrategy configured to use proxy: ${proxy}`)
8080
}
8181
}

packages/apollo-collaboration-server/src/utils/strategies/microsoft.strategy.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from 'node:fs'
33
import { Injectable, Logger } from '@nestjs/common'
44
import { ConfigService } from '@nestjs/config'
55
import { PassportStrategy } from '@nestjs/passport'
6+
import { HttpsProxyAgent } from 'https-proxy-agent'
67
import { Strategy } from 'passport-microsoft'
78

89
import { AuthenticationService } from '../../authentication/authentication.service'
@@ -22,6 +23,7 @@ interface ConfigValues {
2223
MICROSOFT_CLIENT_SECRET_FILE?: string
2324
URL: string
2425
PORT: number
26+
OAUTH_HTTP_PROXY?: string
2527
}
2628

2729
@Injectable()
@@ -72,6 +74,23 @@ export class MicrosoftStrategy extends PassportStrategy(Strategy) {
7274
scope: ['user.read'],
7375
store: true,
7476
})
77+
78+
// Apply proxy to OAuth2 instance
79+
const proxy = configService.get('OAUTH_HTTP_PROXY', { infer: true })
80+
if (proxy) {
81+
const agent = new HttpsProxyAgent(proxy)
82+
83+
// Access the internal OAuth2 instance and set the agent
84+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
85+
const oauth2 = (this as any)._oauth2
86+
if (oauth2) {
87+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
88+
oauth2.setAgent = agent
89+
this.logger.debug(
90+
`Microsoft Strategy configured to use proxy: ${proxy}`,
91+
)
92+
}
93+
}
7594
}
7695

7796
async validate(accessToken: string, refreshToken: string, profile: Profile) {

packages/website/docs/02-installation/04-configuration-options.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ MICROSOFT_CLIENT_SECRET=client_secret_here
105105
# Alternatively, can be a path to a file with a list of plugin URLs, one URL per
106106
# line
107107
# PLUGIN_URLS_FILE=/data/plugin-urls
108+
109+
# HTTP/HTTPS proxy for OAuth requests, if your server is behind a proxy
110+
# OAUTH_HTTP_PROXY=http://proxy.example.com:8080
108111
```

0 commit comments

Comments
 (0)