diff --git a/client/lib/oauthRedirectUri.ts b/client/lib/oauthRedirectUri.ts new file mode 100644 index 000000000000..447340588891 --- /dev/null +++ b/client/lib/oauthRedirectUri.ts @@ -0,0 +1,16 @@ +import { OAuth } from 'meteor/oauth'; + +const { _redirectUri } = OAuth; + +OAuth._redirectUri = (serviceName: string, config: any, params: unknown, absoluteUrlOptions: unknown): string => { + const ret = _redirectUri(serviceName, config, params, absoluteUrlOptions); + + // DEPRECATED: Remove in v5.0.0 + // Meteor 2.3 removed ?close from redirect uri so we need to add it back to not break old oauth clients + // https://github.com/meteor/meteor/commit/b5b7306bedc3e8eb241e64efb1e281925aa75dd3#diff-59244f4e0176cb1beed2e287924e97dc7ae2c0cc51494ce121a85d8937d116a5L11 + if (!config?.loginStyle && !ret.includes('close')) { + return `${ret + (ret.includes('?') ? '&' : '?')}close`; + } + + return ret; +}; diff --git a/client/main.ts b/client/main.ts index e08f775af7de..eae3b5ade5fa 100644 --- a/client/main.ts +++ b/client/main.ts @@ -1,6 +1,7 @@ import '../ee/client/ecdh'; import './polyfills'; +import './lib/oauthRedirectUri'; import './lib/meteorCallWrapper'; import './importPackages'; diff --git a/client/startup/oauth.ts b/client/startup/oauth.ts index 7be58ef055df..23f5ec8246b4 100644 --- a/client/startup/oauth.ts +++ b/client/startup/oauth.ts @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -// @ts-ignore #ToDo: Add definitions for meteor/oauth import { OAuth } from 'meteor/oauth'; // OAuth._retrieveCredentialSecret is a meteor method modified to also check the global localStorage @@ -8,7 +7,7 @@ import { OAuth } from 'meteor/oauth'; Meteor.startup(() => { const meteorOAuthRetrieveCredentialSecret = OAuth._retrieveCredentialSecret; - OAuth._retrieveCredentialSecret = (credentialToken: string): string | undefined => { + OAuth._retrieveCredentialSecret = (credentialToken: string): string | null => { let secret = meteorOAuthRetrieveCredentialSecret.call(OAuth, credentialToken); if (!secret) { const localStorageKey = `${OAuth._storageTokenPrefix}${credentialToken}`; diff --git a/definition/externals/meteor/oauth.d.ts b/definition/externals/meteor/oauth.d.ts new file mode 100644 index 000000000000..67780bcbdb35 --- /dev/null +++ b/definition/externals/meteor/oauth.d.ts @@ -0,0 +1,7 @@ +declare module 'meteor/oauth' { + namespace OAuth { + function _redirectUri(serviceName: string, config: any, params: any, absoluteUrlOptions: any): string; + function _retrieveCredentialSecret(credentialToken: string): string | null; + const _storageTokenPrefix: string; + } +}