From ef16d29405768fe63f0fa3304dced58436fd5385 Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Fri, 6 Sep 2019 11:24:16 -0400 Subject: [PATCH] fix: Omit standard protocol ports from the default hostname (#1543) --- packages/authentication-oauth/src/index.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/authentication-oauth/src/index.ts b/packages/authentication-oauth/src/index.ts index 92290aab06..9ba753b7fb 100644 --- a/packages/authentication-oauth/src/index.ts +++ b/packages/authentication-oauth/src/index.ts @@ -24,18 +24,32 @@ export const setup = (options: OauthSetupSettings) => (app: Application) => { } const { strategyNames } = service; + + // Set up all the defaults const { path = '/oauth' } = oauth.defaults || {}; + const port = app.get('port'); + let host = app.get('host'); + 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({ 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}`; };