From 20cbc880662904e8968bf34ea568a38d10401b52 Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Mon, 2 Sep 2019 19:46:14 -0400 Subject: [PATCH 1/3] Omit standard protocol ports from the default hostname --- packages/authentication-oauth/src/index.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/authentication-oauth/src/index.ts b/packages/authentication-oauth/src/index.ts index 92290aab06..a7f9d59ef2 100644 --- a/packages/authentication-oauth/src/index.ts +++ b/packages/authentication-oauth/src/index.ts @@ -25,17 +25,26 @@ export const setup = (options: OauthSetupSettings) => (app: Application) => { const { strategyNames } = service; const { path = '/oauth' } = oauth.defaults || {}; + const port = String(app.get('port')); + const protocol = app.get('env') === 'production' ? 'https' : 'http'; + + // Omit standard protocol ports from the default hostname + let host = app.get('host'); + if ((protocol === 'https' && port !== '443') || (protocol === 'http' && port !== '80')) { + host += ':' + port; + } + const grant = merge({ defaults: { path, - host: `${app.get('host')}:${app.get('port')}`, - protocol: app.get('env') === 'production' ? 'https' : 'http', + host, + protocol, transport: 'session' } }, omit(oauth, 'redirect')); + const getUrl = (url: string) => { const { defaults } = grant; - return `${defaults.protocol}://${defaults.host}${path}/${url}`; }; From cbb0777c80155f43c46095b804da71ba7c244d56 Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Fri, 6 Sep 2019 11:02:55 -0400 Subject: [PATCH 2/3] Only append the port to the default hostname in dev --- packages/authentication-oauth/src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/authentication-oauth/src/index.ts b/packages/authentication-oauth/src/index.ts index a7f9d59ef2..504c82ac31 100644 --- a/packages/authentication-oauth/src/index.ts +++ b/packages/authentication-oauth/src/index.ts @@ -26,11 +26,12 @@ export const setup = (options: OauthSetupSettings) => (app: Application) => { const { strategyNames } = service; const { path = '/oauth' } = oauth.defaults || {}; const port = String(app.get('port')); - const protocol = app.get('env') === 'production' ? 'https' : 'http'; + const protocol = app.get('env') !== 'development' ? 'https' : 'http'; - // Omit standard protocol ports from the default hostname + // Dev environments commonly run on an extended port, so we need to append the port + // to the default hostname, unless it is the standard port let host = app.get('host'); - if ((protocol === 'https' && port !== '443') || (protocol === 'http' && port !== '80')) { + if (app.get('env') === 'development' && port !== '80') { host += ':' + port; } From 13f66e637123a2f1764df04ca1b391ee5fc0b7fc Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Fri, 6 Sep 2019 11:08:51 -0400 Subject: [PATCH 3/3] Group dev defaults together --- packages/authentication-oauth/src/index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/authentication-oauth/src/index.ts b/packages/authentication-oauth/src/index.ts index 504c82ac31..9ba753b7fb 100644 --- a/packages/authentication-oauth/src/index.ts +++ b/packages/authentication-oauth/src/index.ts @@ -24,15 +24,19 @@ export const setup = (options: OauthSetupSettings) => (app: Application) => { } const { strategyNames } = service; - const { path = '/oauth' } = oauth.defaults || {}; - const port = String(app.get('port')); - const protocol = app.get('env') !== 'development' ? 'https' : 'http'; - // Dev environments commonly run on an extended port, so we need to append the port - // to the default hostname, unless it is the standard port + // Set up all the defaults + const { path = '/oauth' } = oauth.defaults || {}; + const port = app.get('port'); let host = app.get('host'); - if (app.get('env') === 'development' && port !== '80') { - host += ':' + port; + let protocol = 'https'; + + // Development environments commonly run on HTTP with an extended port + if (app.get('env') === 'development') { + protocol = 'http'; + if (String(port) !== '80') { + host += ':' + port; + } } const grant = merge({