From a1686010fa00957abd8e6b26285efe3b979f187e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kosmaty?= Date: Mon, 6 Apr 2020 13:52:21 +0200 Subject: [PATCH 1/4] [expo-auth-session] Fix release channel support --- .../build/ManagedSessionUrlProvider.d.ts | 8 ++- .../build/ManagedSessionUrlProvider.js | 44 ++++++++++----- .../build/ManagedSessionUrlProvider.js.map | 2 +- .../src/ManagedSessionUrlProvider.ts | 55 ++++++++++++------- 4 files changed, 73 insertions(+), 36 deletions(-) diff --git a/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts b/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts index c0e89647a5eb5..00568be7abe05 100644 --- a/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts +++ b/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts @@ -1,14 +1,18 @@ import { SessionUrlProvider } from './SessionUrlProvider'; export declare class ManagedSessionUrlProvider implements SessionUrlProvider { + /** + * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error: + * - `Property 'hostUri' is used before its initialization.` + */ + private static getHostAddress; private static readonly BASE_URL; private static readonly SESSION_PATH; private static readonly USES_CUSTOM_SCHEME; - private static readonly HOST_URI; + private static readonly HOST_ADDRESS; private static readonly IS_EXPO_HOSTED; getDefaultReturnUrl(urlPath?: string): string; getStartUrl(authUrl: string, returnUrl: string): string; getRedirectUrl(): string; - static getHostUri(): string; private static warnIfAnonymous; private static removeScheme; private static removeLeadingSlash; diff --git a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js index 95ceabe8586ef..97d6684ff6c79 100644 --- a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js +++ b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js @@ -2,6 +2,24 @@ import Constants from 'expo-constants'; import qs from 'qs'; const { manifest } = Constants; export class ManagedSessionUrlProvider { + /** + * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error: + * - `Property 'hostUri' is used before its initialization.` + */ + static getHostAddress() { + let hostUri = manifest.hostUri; + if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { + // we're probably not using up-to-date xdl, so just fake it for now + // we have to remove the /--/ on the end since this will be inserted again later + hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(/\/--(\/.*)?$/, ''); + } + const uriParts = hostUri?.split('?'); + const parameters = uriParts?.[1]; + if (uriParts?.length > 0) { + hostUri = uriParts[0]; + } + return { hostUri, parameters }; + } getDefaultReturnUrl(urlPath) { let scheme = 'exp'; let path = ManagedSessionUrlProvider.SESSION_PATH; @@ -15,7 +33,7 @@ export class ManagedSessionUrlProvider { else if (Constants.appOwnership === 'expo' && !manifestScheme) { console.warn('Linking requires that you provide a `scheme` in app.json for standalone apps - if it is left blank, your app may crash. The scheme does not apply to development in the Expo client but you should add it as soon as you start working with Linking to avoid creating a broken build. Add a `scheme` to silence this warning. Learn more about Linking at https://docs.expo.io/versions/latest/workflow/linking/'); } - let hostUri = ManagedSessionUrlProvider.HOST_URI || ''; + let hostUri = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri || ''; if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) { hostUri = ''; } @@ -33,8 +51,15 @@ export class ManagedSessionUrlProvider { if (urlPath) { path = [path, urlPath].filter(Boolean).join('/'); } + let { parameters } = ManagedSessionUrlProvider.HOST_ADDRESS; + if (parameters) { + parameters = `?${parameters}`; + } + else { + parameters = ''; + } hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri); - return encodeURI(`${scheme}://${hostUri}${path}`); + return encodeURI(`${scheme}://${hostUri}${path}${parameters}`); } getStartUrl(authUrl, returnUrl) { const queryString = qs.stringify({ @@ -50,15 +75,6 @@ export class ManagedSessionUrlProvider { } return redirectUrl; } - static getHostUri() { - let hostUri = manifest.hostUri; - if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { - // we're probably not using up-to-date xdl, so just fake it for now - // we have to remove the /--/ on the end since this will be inserted again later - hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(/\/--(\/.*)?$/, ''); - } - return hostUri; - } static warnIfAnonymous(id, url) { if (id.startsWith('@anonymous/')) { console.warn(`You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be "${url}". If you are using an OAuth provider that requires whitelisting redirect URLs, we recommend that you do not whitelist this URL -- instead, you should sign in to Expo to acquired a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`); @@ -77,8 +93,8 @@ export class ManagedSessionUrlProvider { ManagedSessionUrlProvider.BASE_URL = `https://auth.expo.io`; ManagedSessionUrlProvider.SESSION_PATH = 'expo-auth-session'; ManagedSessionUrlProvider.USES_CUSTOM_SCHEME = Constants.appOwnership === 'standalone' && manifest.scheme; -ManagedSessionUrlProvider.HOST_URI = ManagedSessionUrlProvider.getHostUri(); -ManagedSessionUrlProvider.IS_EXPO_HOSTED = ManagedSessionUrlProvider.HOST_URI && - (/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(ManagedSessionUrlProvider.HOST_URI) || +ManagedSessionUrlProvider.HOST_ADDRESS = ManagedSessionUrlProvider.getHostAddress(); +ManagedSessionUrlProvider.IS_EXPO_HOSTED = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri && + (/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(ManagedSessionUrlProvider.HOST_ADDRESS.hostUri) || manifest.developer); //# sourceMappingURL=ManagedSessionUrlProvider.js.map \ No newline at end of file diff --git a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map index fce55a9e1ab0f..d5ca62114f88a 100644 --- a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map +++ b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map @@ -1 +1 @@ -{"version":3,"file":"ManagedSessionUrlProvider.js","sourceRoot":"","sources":["../src/ManagedSessionUrlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAE/B,MAAM,OAAO,yBAAyB;IAapC,mBAAmB,CAAC,OAAgB;QAClC,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAI,IAAI,GAAG,yBAAyB,CAAC,YAAY,CAAC;QAClD,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAEtF,IAAI,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,cAAc,EAAE;YAC7D,MAAM,GAAG,cAAc,CAAC;SACzB;aAAM,IAAI,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,CAAC,cAAc,EAAE;YACrE,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;SACH;aAAM,IAAI,SAAS,CAAC,YAAY,KAAK,MAAM,IAAI,CAAC,cAAc,EAAE;YAC/D,OAAO,CAAC,IAAI,CACV,kZAAkZ,CACnZ,CAAC;SACH;QAED,IAAI,OAAO,GAAG,yBAAyB,CAAC,QAAQ,IAAI,EAAE,CAAC;QACvD,IAAI,yBAAyB,CAAC,kBAAkB,IAAI,yBAAyB,CAAC,cAAc,EAAE;YAC5F,OAAO,GAAG,EAAE,CAAC;SACd;QAED,IAAI,IAAI,EAAE;YACR,IAAI,yBAAyB,CAAC,cAAc,IAAI,OAAO,EAAE;gBACvD,IAAI,GAAG,OAAO,yBAAyB,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;aACpE;YAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,C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AE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YAChC,OAAO,CAAC,IAAI,CACV,+HAA+H,GAAG,yTAAyT,CAC5b,CAAC;SACH;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,GAAW;QACrC,OAAO,GAAG,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAEO,MAAM,CAAC,kBAAkB,CAAC,GAAW;QAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,GAAW;QAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;;AAxGuB,kCAAQ,GAAG,sBAAsB,CAAC;AAClC,sCAAY,GAAG,mBAAmB,CAAC;AACnC,4CAAkB,GACxC,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,QAAQ,CAAC,MAAM,CAAC;AACrC,kCAAQ,GAAG,yBAAyB,CAAC,UAAU,EAAE,CAAC;AAClD,wCAAc,GACpC,yBAAyB,CAAC,QAAQ;IAClC,CAAC,mEAAmE,CAAC,IAAI,CACvE,yBAAyB,CAAC,QAAQ,CACnC;QACC,QAAQ,CAAC,SAAS,CAAC,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport qs from 'qs';\n\nimport { SessionUrlProvider } from './SessionUrlProvider';\n\nconst { manifest } = Constants;\n\nexport class ManagedSessionUrlProvider implements SessionUrlProvider {\n private static readonly BASE_URL = `https://auth.expo.io`;\n private static readonly SESSION_PATH = 'expo-auth-session';\n private static readonly USES_CUSTOM_SCHEME =\n Constants.appOwnership === 'standalone' && manifest.scheme;\n private static readonly HOST_URI = ManagedSessionUrlProvider.getHostUri();\n private static readonly IS_EXPO_HOSTED =\n ManagedSessionUrlProvider.HOST_URI &&\n (/^(.*\\.)?(expo\\.io|exp\\.host|exp\\.direct|expo\\.test)(:.*)?(\\/.*)?$/.test(\n ManagedSessionUrlProvider.HOST_URI\n ) ||\n manifest.developer);\n\n getDefaultReturnUrl(urlPath?: string): string {\n let scheme = 'exp';\n let path = ManagedSessionUrlProvider.SESSION_PATH;\n const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);\n\n if (Constants.appOwnership === 'standalone' && manifestScheme) {\n scheme = manifestScheme;\n } else if (Constants.appOwnership === 'standalone' && !manifestScheme) {\n throw new Error(\n 'Cannot make a deep link into a standalone app with no custom scheme defined'\n );\n } else if (Constants.appOwnership === 'expo' && !manifestScheme) {\n console.warn(\n 'Linking requires that you provide a `scheme` in app.json for standalone apps - if it is left blank, your app may crash. The scheme does not apply to development in the Expo client but you should add it as soon as you start working with Linking to avoid creating a broken build. Add a `scheme` to silence this warning. Learn more about Linking at https://docs.expo.io/versions/latest/workflow/linking/'\n );\n }\n\n let hostUri = ManagedSessionUrlProvider.HOST_URI || '';\n if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) {\n hostUri = '';\n }\n\n if (path) {\n if (ManagedSessionUrlProvider.IS_EXPO_HOSTED && hostUri) {\n path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`;\n }\n\n if (!path.startsWith('/')) {\n path = `/${path}`;\n }\n } else {\n path = '';\n }\n\n if (urlPath) {\n path = [path, urlPath].filter(Boolean).join('/');\n }\n\n hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri);\n\n return encodeURI(`${scheme}://${hostUri}${path}`);\n }\n\n getStartUrl(authUrl: string, returnUrl: string): string {\n const queryString = qs.stringify({\n authUrl,\n returnUrl,\n });\n\n return `${this.getRedirectUrl()}/start?${queryString}`;\n }\n\n getRedirectUrl(): string {\n const redirectUrl = `${ManagedSessionUrlProvider.BASE_URL}/${manifest.id}`;\n if (__DEV__) {\n ManagedSessionUrlProvider.warnIfAnonymous(manifest.id, redirectUrl);\n }\n return redirectUrl;\n }\n\n static getHostUri(): string {\n let hostUri = manifest.hostUri;\n if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) {\n // we're probably not using up-to-date xdl, so just fake it for now\n // we have to remove the /--/ on the end since this will be inserted again later\n hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(\n /\\/--(\\/.*)?$/,\n ''\n );\n }\n\n return hostUri;\n }\n\n private static warnIfAnonymous(id, url): void {\n if (id.startsWith('@anonymous/')) {\n console.warn(\n `You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be \"${url}\". If you are using an OAuth provider that requires whitelisting redirect URLs, we recommend that you do not whitelist this URL -- instead, you should sign in to Expo to acquired a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`\n );\n }\n }\n\n private static removeScheme(url: string) {\n return url.replace(/^[a-zA-Z0-9+.-]+:\\/\\//, '');\n }\n\n private static removeLeadingSlash(url: string) {\n return url.replace(/^\\//, '');\n }\n\n private static removeTrailingSlash(url: string) {\n return url.replace(/\\/$/, '');\n }\n}\n"]} \ No newline at end of file +{"version":3,"file":"ManagedSessionUrlProvider.js","sourceRoot":"","sources":["../src/ManagedSessionUrlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAE/B,MAAM,OAAO,yBAAyB;IACpC;;;OAGG;IACK,MAAM,CAAC,cAAc;QAC3B,IAAI,OAAO,GAAW,QAAQ,CAAC,OAAO,CAAC;QACvC,IAAI,CAAC,OAAO,IAAI,CAAC,yBAAyB,CAAC,kBAAkB,EAAE;YAC7D,mEAAmE;YACnE,gFAAgF;YAChF,OAAO,GAAG,yBAAyB,CAAC,YAAY,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,OAAO,CAC5E,cAAc,EACd,EAAE,CACH,CAAC;SACH;QAED,MAAM,QAAQ,GAAG,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C,YAAY,CAAC,GAAW;QACrC,OAAO,GAAG,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAEO,MAAM,CAAC,kBAAkB,CAAC,GAAW;QAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,GAAW;QAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;;AAjGuB,kCAAQ,GAAG,sBAAsB,CAAC;AAClC,sCAAY,GAAG,mBAAmB,CAAC;AACnC,4CAAkB,GACxC,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,QAAQ,CAAC,MAAM,CAAC;AACrC,sCAAY,GAAG,yBAAyB,CAAC,cAAc,EAAE,CAAC;AAC1D,wCAAc,GACpC,yBAAyB,CAAC,YAAY,CAAC,OAAO;IAC9C,CAAC,mEAAmE,CAAC,IAAI,CACvE,yBAAyB,CAAC,YAAY,CAAC,OAAO,CAC/C;QACC,QAAQ,CAAC,SAAS,CAAC,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport qs from 'qs';\n\nimport { SessionUrlProvider } from './SessionUrlProvider';\n\nconst { manifest } = Constants;\n\nexport class ManagedSessionUrlProvider implements SessionUrlProvider {\n /**\n * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error:\n * - `Property 'hostUri' is used before its initialization.`\n */\n private static getHostAddress(): { hostUri: string; parameters: string | undefined } {\n let hostUri: string = manifest.hostUri;\n if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) {\n // we're probably not using up-to-date xdl, so just fake it for now\n // we have to remove the /--/ on the end since this will be inserted again later\n hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(\n /\\/--(\\/.*)?$/,\n ''\n );\n }\n\n const uriParts = hostUri?.split('?');\n const parameters = uriParts?.[1];\n if (uriParts?.length > 0) {\n hostUri = uriParts[0];\n }\n\n return { hostUri, parameters };\n }\n\n private static readonly BASE_URL = `https://auth.expo.io`;\n private static readonly SESSION_PATH = 'expo-auth-session';\n private static readonly USES_CUSTOM_SCHEME =\n Constants.appOwnership === 'standalone' && manifest.scheme;\n private static readonly HOST_ADDRESS = ManagedSessionUrlProvider.getHostAddress();\n private static readonly IS_EXPO_HOSTED =\n ManagedSessionUrlProvider.HOST_ADDRESS.hostUri &&\n (/^(.*\\.)?(expo\\.io|exp\\.host|exp\\.direct|expo\\.test)(:.*)?(\\/.*)?$/.test(\n ManagedSessionUrlProvider.HOST_ADDRESS.hostUri\n ) ||\n manifest.developer);\n\n getDefaultReturnUrl(urlPath?: string): string {\n let scheme = 'exp';\n let path = ManagedSessionUrlProvider.SESSION_PATH;\n const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);\n\n if (Constants.appOwnership === 'standalone' && manifestScheme) {\n scheme = manifestScheme;\n } else if (Constants.appOwnership === 'standalone' && !manifestScheme) {\n throw new Error(\n 'Cannot make a deep link into a standalone app with no custom scheme defined'\n );\n } else if (Constants.appOwnership === 'expo' && !manifestScheme) {\n console.warn(\n 'Linking requires that you provide a `scheme` in app.json for standalone apps - if it is left blank, your app may crash. The scheme does not apply to development in the Expo client but you should add it as soon as you start working with Linking to avoid creating a broken build. Add a `scheme` to silence this warning. Learn more about Linking at https://docs.expo.io/versions/latest/workflow/linking/'\n );\n }\n\n let hostUri = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri || '';\n if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) {\n hostUri = '';\n }\n\n if (path) {\n if (ManagedSessionUrlProvider.IS_EXPO_HOSTED && hostUri) {\n path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`;\n }\n\n if (!path.startsWith('/')) {\n path = `/${path}`;\n }\n } else {\n path = '';\n }\n\n if (urlPath) {\n path = [path, urlPath].filter(Boolean).join('/');\n }\n\n let { parameters } = ManagedSessionUrlProvider.HOST_ADDRESS;\n if (parameters) {\n parameters = `?${parameters}`;\n } else {\n parameters = '';\n }\n\n hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri);\n\n return encodeURI(`${scheme}://${hostUri}${path}${parameters}`);\n }\n\n getStartUrl(authUrl: string, returnUrl: string): string {\n const queryString = qs.stringify({\n authUrl,\n returnUrl,\n });\n\n return `${this.getRedirectUrl()}/start?${queryString}`;\n }\n\n getRedirectUrl(): string {\n const redirectUrl = `${ManagedSessionUrlProvider.BASE_URL}/${manifest.id}`;\n if (__DEV__) {\n ManagedSessionUrlProvider.warnIfAnonymous(manifest.id, redirectUrl);\n }\n return redirectUrl;\n }\n\n private static warnIfAnonymous(id, url): void {\n if (id.startsWith('@anonymous/')) {\n console.warn(\n `You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be \"${url}\". If you are using an OAuth provider that requires whitelisting redirect URLs, we recommend that you do not whitelist this URL -- instead, you should sign in to Expo to acquired a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`\n );\n }\n }\n\n private static removeScheme(url: string) {\n return url.replace(/^[a-zA-Z0-9+.-]+:\\/\\//, '');\n }\n\n private static removeLeadingSlash(url: string) {\n return url.replace(/^\\//, '');\n }\n\n private static removeTrailingSlash(url: string) {\n return url.replace(/\\/$/, '');\n }\n}\n"]} \ No newline at end of file diff --git a/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts b/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts index f68757df37094..e33c89b9ae670 100644 --- a/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts +++ b/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts @@ -6,15 +6,39 @@ import { SessionUrlProvider } from './SessionUrlProvider'; const { manifest } = Constants; export class ManagedSessionUrlProvider implements SessionUrlProvider { + /** + * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error: + * - `Property 'hostUri' is used before its initialization.` + */ + private static getHostAddress(): { hostUri: string; parameters: string | undefined } { + let hostUri: string = manifest.hostUri; + if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { + // we're probably not using up-to-date xdl, so just fake it for now + // we have to remove the /--/ on the end since this will be inserted again later + hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace( + /\/--(\/.*)?$/, + '' + ); + } + + const uriParts = hostUri?.split('?'); + const parameters = uriParts?.[1]; + if (uriParts?.length > 0) { + hostUri = uriParts[0]; + } + + return { hostUri, parameters }; + } + private static readonly BASE_URL = `https://auth.expo.io`; private static readonly SESSION_PATH = 'expo-auth-session'; private static readonly USES_CUSTOM_SCHEME = Constants.appOwnership === 'standalone' && manifest.scheme; - private static readonly HOST_URI = ManagedSessionUrlProvider.getHostUri(); + private static readonly HOST_ADDRESS = ManagedSessionUrlProvider.getHostAddress(); private static readonly IS_EXPO_HOSTED = - ManagedSessionUrlProvider.HOST_URI && + ManagedSessionUrlProvider.HOST_ADDRESS.hostUri && (/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test( - ManagedSessionUrlProvider.HOST_URI + ManagedSessionUrlProvider.HOST_ADDRESS.hostUri ) || manifest.developer); @@ -35,7 +59,7 @@ export class ManagedSessionUrlProvider implements SessionUrlProvider { ); } - let hostUri = ManagedSessionUrlProvider.HOST_URI || ''; + let hostUri = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri || ''; if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) { hostUri = ''; } @@ -56,9 +80,16 @@ export class ManagedSessionUrlProvider implements SessionUrlProvider { path = [path, urlPath].filter(Boolean).join('/'); } + let { parameters } = ManagedSessionUrlProvider.HOST_ADDRESS; + if (parameters) { + parameters = `?${parameters}`; + } else { + parameters = ''; + } + hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri); - return encodeURI(`${scheme}://${hostUri}${path}`); + return encodeURI(`${scheme}://${hostUri}${path}${parameters}`); } getStartUrl(authUrl: string, returnUrl: string): string { @@ -78,20 +109,6 @@ export class ManagedSessionUrlProvider implements SessionUrlProvider { return redirectUrl; } - static getHostUri(): string { - let hostUri = manifest.hostUri; - if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { - // we're probably not using up-to-date xdl, so just fake it for now - // we have to remove the /--/ on the end since this will be inserted again later - hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace( - /\/--(\/.*)?$/, - '' - ); - } - - return hostUri; - } - private static warnIfAnonymous(id, url): void { if (id.startsWith('@anonymous/')) { console.warn( From a7be8b69f3c6d8a8750cae62f48e0b485b0cbcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kosmaty?= Date: Mon, 6 Apr 2020 14:01:51 +0200 Subject: [PATCH 2/4] [expo-auth-session] Update changelog --- packages/expo-auth-session/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/expo-auth-session/CHANGELOG.md b/packages/expo-auth-session/CHANGELOG.md index 6a294c6841ff4..b234c9c6bc4d3 100644 --- a/packages/expo-auth-session/CHANGELOG.md +++ b/packages/expo-auth-session/CHANGELOG.md @@ -7,3 +7,5 @@ ### 🎉 New features ### 🐛 Bug fixes + +- Fix `AuthSession.getDefaultReturnUrl()` returning wrong URL while using releas channels. ([#7687](https://github.com/expo/expo/pull/7687) by [@lukmccall](https://github.com/lukmccall)) From 2b9788f7475687256292cdf4e5479664bc9c73f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kosmaty?= Date: Thu, 9 Apr 2020 12:43:07 +0200 Subject: [PATCH 3/4] [expo-auth-session] Fix typo --- packages/expo-auth-session/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/expo-auth-session/CHANGELOG.md b/packages/expo-auth-session/CHANGELOG.md index b234c9c6bc4d3..aaaf366a9af9b 100644 --- a/packages/expo-auth-session/CHANGELOG.md +++ b/packages/expo-auth-session/CHANGELOG.md @@ -8,4 +8,4 @@ ### 🐛 Bug fixes -- Fix `AuthSession.getDefaultReturnUrl()` returning wrong URL while using releas channels. ([#7687](https://github.com/expo/expo/pull/7687) by [@lukmccall](https://github.com/lukmccall)) +- Fix `AuthSession.getDefaultReturnUrl()` returning wrong URL while using release channels. ([#7687](https://github.com/expo/expo/pull/7687) by [@lukmccall](https://github.com/lukmccall)) From 60d83b0b0ffca63569b9ebef5c70b89b1790b52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kosmaty?= Date: Thu, 9 Apr 2020 14:49:13 +0200 Subject: [PATCH 4/4] [expo-auth-session] Add tests --- .../build/ManagedSessionUrlProvider.d.ts | 8 +-- .../build/ManagedSessionUrlProvider.js | 48 ++++++------- .../build/ManagedSessionUrlProvider.js.map | 2 +- .../src/ManagedSessionUrlProvider.ts | 68 +++++++++---------- ...r.ts => ManagedSessionUrlProvider-test.ts} | 24 +++++++ 5 files changed, 80 insertions(+), 70 deletions(-) rename packages/expo-auth-session/src/__tests__/{ManagedSessionUrlProvider.ts => ManagedSessionUrlProvider-test.ts} (54%) diff --git a/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts b/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts index 00568be7abe05..fe18ba0311e8b 100644 --- a/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts +++ b/packages/expo-auth-session/build/ManagedSessionUrlProvider.d.ts @@ -1,18 +1,12 @@ import { SessionUrlProvider } from './SessionUrlProvider'; export declare class ManagedSessionUrlProvider implements SessionUrlProvider { - /** - * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error: - * - `Property 'hostUri' is used before its initialization.` - */ - private static getHostAddress; private static readonly BASE_URL; private static readonly SESSION_PATH; private static readonly USES_CUSTOM_SCHEME; - private static readonly HOST_ADDRESS; - private static readonly IS_EXPO_HOSTED; getDefaultReturnUrl(urlPath?: string): string; getStartUrl(authUrl: string, returnUrl: string): string; getRedirectUrl(): string; + private static getHostAddress; private static warnIfAnonymous; private static removeScheme; private static removeLeadingSlash; diff --git a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js index 97d6684ff6c79..efa80320fb59b 100644 --- a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js +++ b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js @@ -2,25 +2,11 @@ import Constants from 'expo-constants'; import qs from 'qs'; const { manifest } = Constants; export class ManagedSessionUrlProvider { - /** - * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error: - * - `Property 'hostUri' is used before its initialization.` - */ - static getHostAddress() { - let hostUri = manifest.hostUri; - if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { - // we're probably not using up-to-date xdl, so just fake it for now - // we have to remove the /--/ on the end since this will be inserted again later - hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(/\/--(\/.*)?$/, ''); - } - const uriParts = hostUri?.split('?'); - const parameters = uriParts?.[1]; - if (uriParts?.length > 0) { - hostUri = uriParts[0]; - } - return { hostUri, parameters }; - } getDefaultReturnUrl(urlPath) { + const hostAddress = ManagedSessionUrlProvider.getHostAddress(); + const isExpoHosted = hostAddress.hostUri && + (/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(hostAddress.hostUri) || + manifest.developer); let scheme = 'exp'; let path = ManagedSessionUrlProvider.SESSION_PATH; const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme); @@ -33,12 +19,12 @@ export class ManagedSessionUrlProvider { else if (Constants.appOwnership === 'expo' && !manifestScheme) { console.warn('Linking requires that you provide a `scheme` in app.json for standalone apps - if it is left blank, your app may crash. The scheme does not apply to development in the Expo client but you should add it as soon as you start working with Linking to avoid creating a broken build. Add a `scheme` to silence this warning. Learn more about Linking at https://docs.expo.io/versions/latest/workflow/linking/'); } - let hostUri = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri || ''; - if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) { + let hostUri = hostAddress.hostUri || ''; + if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && isExpoHosted) { hostUri = ''; } if (path) { - if (ManagedSessionUrlProvider.IS_EXPO_HOSTED && hostUri) { + if (isExpoHosted && hostUri) { path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`; } if (!path.startsWith('/')) { @@ -51,7 +37,7 @@ export class ManagedSessionUrlProvider { if (urlPath) { path = [path, urlPath].filter(Boolean).join('/'); } - let { parameters } = ManagedSessionUrlProvider.HOST_ADDRESS; + let { parameters } = hostAddress; if (parameters) { parameters = `?${parameters}`; } @@ -75,6 +61,20 @@ export class ManagedSessionUrlProvider { } return redirectUrl; } + static getHostAddress() { + let hostUri = Constants.manifest.hostUri; + if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { + // we're probably not using up-to-date xdl, so just fake it for now + // we have to remove the /--/ on the end since this will be inserted again later + hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(/\/--(\/.*)?$/, ''); + } + const uriParts = hostUri?.split('?'); + const parameters = uriParts?.[1]; + if (uriParts?.length > 0) { + hostUri = uriParts[0]; + } + return { hostUri, parameters }; + } static warnIfAnonymous(id, url) { if (id.startsWith('@anonymous/')) { console.warn(`You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be "${url}". If you are using an OAuth provider that requires whitelisting redirect URLs, we recommend that you do not whitelist this URL -- instead, you should sign in to Expo to acquired a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`); @@ -93,8 +93,4 @@ export class ManagedSessionUrlProvider { ManagedSessionUrlProvider.BASE_URL = `https://auth.expo.io`; ManagedSessionUrlProvider.SESSION_PATH = 'expo-auth-session'; ManagedSessionUrlProvider.USES_CUSTOM_SCHEME = Constants.appOwnership === 'standalone' && manifest.scheme; -ManagedSessionUrlProvider.HOST_ADDRESS = ManagedSessionUrlProvider.getHostAddress(); -ManagedSessionUrlProvider.IS_EXPO_HOSTED = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri && - (/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(ManagedSessionUrlProvider.HOST_ADDRESS.hostUri) || - manifest.developer); //# sourceMappingURL=ManagedSessionUrlProvider.js.map \ No newline at end of file diff --git a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map index d5ca62114f88a..08d92856ec191 100644 --- a/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map +++ b/packages/expo-auth-session/build/ManagedSessionUrlProvider.js.map @@ -1 +1 @@ -{"version":3,"file":"ManagedSessionUrlProvider.js","sourceRoot":"","sources":["../src/ManagedSessionUrlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAE/B,MAAM,OAAO,yBAAyB;IACpC;;;OAGG;IACK,MAAM,CAAC,cAAc;QAC3B,IAAI,OAAO,GAAW,QAAQ,CAAC,OAAO,CAAC;QACvC,IAAI,CAAC,OAAO,IAAI,CAAC,yBAAyB,CAAC,kBAAkB,EAAE;YAC7D,mEAAmE;YACnE,gFAAgF;YAChF,OAAO,GAAG,yBAAyB,CAAC,YAAY,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,OAAO,CAC5E,cAAc,EACd,EAAE,CACH,CAAC;SACH;QAED,MAAM,QAAQ,GAAG,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,QAAQ,EAAE,MA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C,GAAW;QAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,GAAW;QAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;;AAjGuB,kCAAQ,GAAG,sBAAsB,CAAC;AAClC,sCAAY,GAAG,mBAAmB,CAAC;AACnC,4CAAkB,GACxC,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,QAAQ,CAAC,MAAM,CAAC;AACrC,sCAAY,GAAG,yBAAyB,CAAC,cAAc,EAAE,CAAC;AAC1D,wCAAc,GACpC,yBAAyB,CAAC,YAAY,CAAC,OAAO;IAC9C,CAAC,mEAAmE,CAAC,IAAI,CACvE,yBAAyB,CAAC,YAAY,CAAC,OAAO,CAC/C;QACC,QAAQ,CAAC,SAAS,CAAC,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport qs from 'qs';\n\nimport { SessionUrlProvider } from './SessionUrlProvider';\n\nconst { manifest } = Constants;\n\nexport class ManagedSessionUrlProvider implements SessionUrlProvider {\n /**\n * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error:\n * - `Property 'hostUri' is used before its initialization.`\n */\n private static getHostAddress(): { hostUri: string; parameters: string | undefined } {\n let hostUri: string = manifest.hostUri;\n if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) {\n // we're probably not using up-to-date xdl, so just fake it for now\n // we have to remove the /--/ on the end since this will be inserted again later\n hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(\n /\\/--(\\/.*)?$/,\n ''\n );\n }\n\n const uriParts = hostUri?.split('?');\n const parameters = uriParts?.[1];\n if (uriParts?.length > 0) {\n hostUri = uriParts[0];\n }\n\n return { hostUri, parameters };\n }\n\n private static readonly BASE_URL = `https://auth.expo.io`;\n private static readonly SESSION_PATH = 'expo-auth-session';\n private static readonly USES_CUSTOM_SCHEME =\n Constants.appOwnership === 'standalone' && manifest.scheme;\n private static readonly HOST_ADDRESS = ManagedSessionUrlProvider.getHostAddress();\n private static readonly IS_EXPO_HOSTED =\n ManagedSessionUrlProvider.HOST_ADDRESS.hostUri &&\n (/^(.*\\.)?(expo\\.io|exp\\.host|exp\\.direct|expo\\.test)(:.*)?(\\/.*)?$/.test(\n ManagedSessionUrlProvider.HOST_ADDRESS.hostUri\n ) ||\n manifest.developer);\n\n getDefaultReturnUrl(urlPath?: string): string {\n let scheme = 'exp';\n let path = ManagedSessionUrlProvider.SESSION_PATH;\n const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);\n\n if (Constants.appOwnership === 'standalone' && manifestScheme) {\n scheme = manifestScheme;\n } else if (Constants.appOwnership === 'standalone' && !manifestScheme) {\n throw new Error(\n 'Cannot make a deep link into a standalone app with no custom scheme defined'\n );\n } else if (Constants.appOwnership === 'expo' && !manifestScheme) {\n console.warn(\n 'Linking requires that you provide a `scheme` in app.json for standalone apps - if it is left blank, your app may crash. The scheme does not apply to development in the Expo client but you should add it as soon as you start working with Linking to avoid creating a broken build. Add a `scheme` to silence this warning. Learn more about Linking at https://docs.expo.io/versions/latest/workflow/linking/'\n );\n }\n\n let hostUri = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri || '';\n if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) {\n hostUri = '';\n }\n\n if (path) {\n if (ManagedSessionUrlProvider.IS_EXPO_HOSTED && hostUri) {\n path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`;\n }\n\n if (!path.startsWith('/')) {\n path = `/${path}`;\n }\n } else {\n path = '';\n }\n\n if (urlPath) {\n path = [path, urlPath].filter(Boolean).join('/');\n }\n\n let { parameters } = ManagedSessionUrlProvider.HOST_ADDRESS;\n if (parameters) {\n parameters = `?${parameters}`;\n } else {\n parameters = '';\n }\n\n hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri);\n\n return encodeURI(`${scheme}://${hostUri}${path}${parameters}`);\n }\n\n getStartUrl(authUrl: string, returnUrl: string): string {\n const queryString = qs.stringify({\n authUrl,\n returnUrl,\n });\n\n return `${this.getRedirectUrl()}/start?${queryString}`;\n }\n\n getRedirectUrl(): string {\n const redirectUrl = `${ManagedSessionUrlProvider.BASE_URL}/${manifest.id}`;\n if (__DEV__) {\n ManagedSessionUrlProvider.warnIfAnonymous(manifest.id, redirectUrl);\n }\n return redirectUrl;\n }\n\n private static warnIfAnonymous(id, url): void {\n if (id.startsWith('@anonymous/')) {\n console.warn(\n `You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be \"${url}\". If you are using an OAuth provider that requires whitelisting redirect URLs, we recommend that you do not whitelist this URL -- instead, you should sign in to Expo to acquired a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`\n );\n }\n }\n\n private static removeScheme(url: string) {\n return url.replace(/^[a-zA-Z0-9+.-]+:\\/\\//, '');\n }\n\n private static removeLeadingSlash(url: string) {\n return url.replace(/^\\//, '');\n }\n\n private static removeTrailingSlash(url: string) {\n return url.replace(/\\/$/, '');\n }\n}\n"]} \ No newline at end of file +{"version":3,"file":"ManagedSessionUrlProvider.js","sourceRoot":"","sources":["../src/ManagedSessionUrlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAE/B,MAAM,OAAO,yBAAyB;IAMpC,mBAAmB,CAAC,OAAgB;QAClC,MAAM,WAAW,GAAG,yBAAyB,CAAC,cAAc,EAAE,CAAC;QAC/D,MAAM,YAAY,GAChB,WAAW,CAAC,OAAO;YACnB,CAAC,mEAAmE,CAAC,IAAI,CACvE,WAAW,CAAC,OAAO,CACpB;gBACC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAExB,IAAI,MAA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EAAE,CAAC;IACjC,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG;QACpC,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YAChC,OAAO,CAAC,IAAI,CACV,+HAA+H,GAAG,yTAAyT,CAC5b,CAAC;SACH;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,GAAW;QACrC,OAAO,GAAG,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAEO,MAAM,CAAC,kBAAkB,CAAC,GAAW;QAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,GAAW;QAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;;AArHuB,kCAAQ,GAAG,sBAAsB,CAAC;AAClC,sCAAY,GAAG,mBAAmB,CAAC;AACnC,4CAAkB,GACxC,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,QAAQ,CAAC,MAAM,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport qs from 'qs';\n\nimport { SessionUrlProvider } from './SessionUrlProvider';\n\nconst { manifest } = Constants;\n\nexport class ManagedSessionUrlProvider implements SessionUrlProvider {\n private static readonly BASE_URL = `https://auth.expo.io`;\n private static readonly SESSION_PATH = 'expo-auth-session';\n private static readonly USES_CUSTOM_SCHEME =\n Constants.appOwnership === 'standalone' && manifest.scheme;\n\n getDefaultReturnUrl(urlPath?: string): string {\n const hostAddress = ManagedSessionUrlProvider.getHostAddress();\n const isExpoHosted =\n hostAddress.hostUri &&\n (/^(.*\\.)?(expo\\.io|exp\\.host|exp\\.direct|expo\\.test)(:.*)?(\\/.*)?$/.test(\n hostAddress.hostUri\n ) ||\n manifest.developer);\n\n let scheme = 'exp';\n let path = ManagedSessionUrlProvider.SESSION_PATH;\n const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);\n\n if (Constants.appOwnership === 'standalone' && manifestScheme) {\n scheme = manifestScheme;\n } else if (Constants.appOwnership === 'standalone' && !manifestScheme) {\n throw new Error(\n 'Cannot make a deep link into a standalone app with no custom scheme defined'\n );\n } else if (Constants.appOwnership === 'expo' && !manifestScheme) {\n console.warn(\n 'Linking requires that you provide a `scheme` in app.json for standalone apps - if it is left blank, your app may crash. The scheme does not apply to development in the Expo client but you should add it as soon as you start working with Linking to avoid creating a broken build. Add a `scheme` to silence this warning. Learn more about Linking at https://docs.expo.io/versions/latest/workflow/linking/'\n );\n }\n\n let hostUri = hostAddress.hostUri || '';\n if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && isExpoHosted) {\n hostUri = '';\n }\n\n if (path) {\n if (isExpoHosted && hostUri) {\n path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`;\n }\n\n if (!path.startsWith('/')) {\n path = `/${path}`;\n }\n } else {\n path = '';\n }\n\n if (urlPath) {\n path = [path, urlPath].filter(Boolean).join('/');\n }\n\n let { parameters } = hostAddress;\n if (parameters) {\n parameters = `?${parameters}`;\n } else {\n parameters = '';\n }\n\n hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri);\n return encodeURI(`${scheme}://${hostUri}${path}${parameters}`);\n }\n\n getStartUrl(authUrl: string, returnUrl: string): string {\n const queryString = qs.stringify({\n authUrl,\n returnUrl,\n });\n\n return `${this.getRedirectUrl()}/start?${queryString}`;\n }\n\n getRedirectUrl(): string {\n const redirectUrl = `${ManagedSessionUrlProvider.BASE_URL}/${manifest.id}`;\n if (__DEV__) {\n ManagedSessionUrlProvider.warnIfAnonymous(manifest.id, redirectUrl);\n }\n return redirectUrl;\n }\n\n private static getHostAddress(): { hostUri: string; parameters: string | undefined } {\n let hostUri: string = Constants.manifest.hostUri;\n if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) {\n // we're probably not using up-to-date xdl, so just fake it for now\n // we have to remove the /--/ on the end since this will be inserted again later\n hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace(\n /\\/--(\\/.*)?$/,\n ''\n );\n }\n\n const uriParts = hostUri?.split('?');\n const parameters = uriParts?.[1];\n if (uriParts?.length > 0) {\n hostUri = uriParts[0];\n }\n\n return { hostUri, parameters };\n }\n\n private static warnIfAnonymous(id, url): void {\n if (id.startsWith('@anonymous/')) {\n console.warn(\n `You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be \"${url}\". If you are using an OAuth provider that requires whitelisting redirect URLs, we recommend that you do not whitelist this URL -- instead, you should sign in to Expo to acquired a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`\n );\n }\n }\n\n private static removeScheme(url: string) {\n return url.replace(/^[a-zA-Z0-9+.-]+:\\/\\//, '');\n }\n\n private static removeLeadingSlash(url: string) {\n return url.replace(/^\\//, '');\n }\n\n private static removeTrailingSlash(url: string) {\n return url.replace(/\\/$/, '');\n }\n}\n"]} \ No newline at end of file diff --git a/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts b/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts index e33c89b9ae670..dccf3ad96098c 100644 --- a/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts +++ b/packages/expo-auth-session/src/ManagedSessionUrlProvider.ts @@ -6,43 +6,20 @@ import { SessionUrlProvider } from './SessionUrlProvider'; const { manifest } = Constants; export class ManagedSessionUrlProvider implements SessionUrlProvider { - /** - * This method was moved to the top of this class, cause otherwise, ts compilation will fail with error: - * - `Property 'hostUri' is used before its initialization.` - */ - private static getHostAddress(): { hostUri: string; parameters: string | undefined } { - let hostUri: string = manifest.hostUri; - if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { - // we're probably not using up-to-date xdl, so just fake it for now - // we have to remove the /--/ on the end since this will be inserted again later - hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace( - /\/--(\/.*)?$/, - '' - ); - } - - const uriParts = hostUri?.split('?'); - const parameters = uriParts?.[1]; - if (uriParts?.length > 0) { - hostUri = uriParts[0]; - } - - return { hostUri, parameters }; - } - private static readonly BASE_URL = `https://auth.expo.io`; private static readonly SESSION_PATH = 'expo-auth-session'; private static readonly USES_CUSTOM_SCHEME = Constants.appOwnership === 'standalone' && manifest.scheme; - private static readonly HOST_ADDRESS = ManagedSessionUrlProvider.getHostAddress(); - private static readonly IS_EXPO_HOSTED = - ManagedSessionUrlProvider.HOST_ADDRESS.hostUri && - (/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test( - ManagedSessionUrlProvider.HOST_ADDRESS.hostUri - ) || - manifest.developer); getDefaultReturnUrl(urlPath?: string): string { + const hostAddress = ManagedSessionUrlProvider.getHostAddress(); + const isExpoHosted = + hostAddress.hostUri && + (/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test( + hostAddress.hostUri + ) || + manifest.developer); + let scheme = 'exp'; let path = ManagedSessionUrlProvider.SESSION_PATH; const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme); @@ -59,13 +36,13 @@ export class ManagedSessionUrlProvider implements SessionUrlProvider { ); } - let hostUri = ManagedSessionUrlProvider.HOST_ADDRESS.hostUri || ''; - if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) { + let hostUri = hostAddress.hostUri || ''; + if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && isExpoHosted) { hostUri = ''; } if (path) { - if (ManagedSessionUrlProvider.IS_EXPO_HOSTED && hostUri) { + if (isExpoHosted && hostUri) { path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`; } @@ -80,7 +57,7 @@ export class ManagedSessionUrlProvider implements SessionUrlProvider { path = [path, urlPath].filter(Boolean).join('/'); } - let { parameters } = ManagedSessionUrlProvider.HOST_ADDRESS; + let { parameters } = hostAddress; if (parameters) { parameters = `?${parameters}`; } else { @@ -88,7 +65,6 @@ export class ManagedSessionUrlProvider implements SessionUrlProvider { } hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri); - return encodeURI(`${scheme}://${hostUri}${path}${parameters}`); } @@ -109,6 +85,26 @@ export class ManagedSessionUrlProvider implements SessionUrlProvider { return redirectUrl; } + private static getHostAddress(): { hostUri: string; parameters: string | undefined } { + let hostUri: string = Constants.manifest.hostUri; + if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) { + // we're probably not using up-to-date xdl, so just fake it for now + // we have to remove the /--/ on the end since this will be inserted again later + hostUri = ManagedSessionUrlProvider.removeScheme(Constants.linkingUri).replace( + /\/--(\/.*)?$/, + '' + ); + } + + const uriParts = hostUri?.split('?'); + const parameters = uriParts?.[1]; + if (uriParts?.length > 0) { + hostUri = uriParts[0]; + } + + return { hostUri, parameters }; + } + private static warnIfAnonymous(id, url): void { if (id.startsWith('@anonymous/')) { console.warn( diff --git a/packages/expo-auth-session/src/__tests__/ManagedSessionUrlProvider.ts b/packages/expo-auth-session/src/__tests__/ManagedSessionUrlProvider-test.ts similarity index 54% rename from packages/expo-auth-session/src/__tests__/ManagedSessionUrlProvider.ts rename to packages/expo-auth-session/src/__tests__/ManagedSessionUrlProvider-test.ts index b41b731c9f76e..da58ded7c5f86 100644 --- a/packages/expo-auth-session/src/__tests__/ManagedSessionUrlProvider.ts +++ b/packages/expo-auth-session/src/__tests__/ManagedSessionUrlProvider-test.ts @@ -25,3 +25,27 @@ it(`returns the correct start URL from getStartUrl`, () => { 'https://auth.expo.io/@example/abc/start?authUrl=https%3A%2F%2Fsignin.com&returnUrl=exp%3A%2F%2Fexpo.io%2F%40example%2Fabc%2B' ); }); + +describe(`getDefaultReturnUrl`, () => { + it(`checks return url`, () => { + mockProperty(Constants.manifest, 'hostUri', 'exp.host/@example/abc'); + + const result = managedSessionUrlProvider.getDefaultReturnUrl(); + + expect(result).toEqual('exp://exp.host/@example/abc/--/expo-auth-session'); + }); + + it(`checks url with the release chanel`, () => { + mockProperty( + Constants.manifest, + 'hostUri', + 'exp.host/@example/abc?release-chanel=release-chanel' + ); + + const result = managedSessionUrlProvider.getDefaultReturnUrl(); + + expect(result).toEqual( + 'exp://exp.host/@example/abc/--/expo-auth-session?release-chanel=release-chanel' + ); + }); +});