From f0c28d06aeaa67efd4ae8fa1802e601ec212ee06 Mon Sep 17 00:00:00 2001 From: Alexis Venner Date: Wed, 22 Jan 2020 13:16:54 +0100 Subject: [PATCH 1/4] Supports ephemeralWebBrowserSession on iOS 13 Hello, Actually, on iOS 12+, when you login, the cookie is kept until the app is killed. Since iOS 13 it's possible to make session ephemeral. With this option prefersEphemeralWebBrowserSession, the cookie is killed when tab browser is closed. Pros : - no need to logout manualy users (for account switch for example) Cons : - user should reconnect each time the tab is presented. It fix https://github.com/proyecto26/react-native-inappbrowser/issues/76 , on iOS 13. TODO : Improvement : make this parameter as an option Best Regards --- ios/RNInAppBrowser.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ios/RNInAppBrowser.m b/ios/RNInAppBrowser.m index d8188a0..d7aa754 100644 --- a/ios/RNInAppBrowser.m +++ b/ios/RNInAppBrowser.m @@ -92,6 +92,10 @@ + (BOOL)requiresMainQueueSetup initWithURL:url callbackURLScheme:redirectURL completionHandler:completionHandler]; + + if (@available(iOS 13.0, *)) { + webAuthSession.prefersEphemeralWebBrowserSession = true; + } } else { authSession = [[SFAuthenticationSession alloc] initWithURL:url From 724e76f2dfa275954cf70a53aad0b108839eb37e Mon Sep 17 00:00:00 2001 From: Alexis Venner Date: Tue, 11 Feb 2020 19:11:32 +0100 Subject: [PATCH 2/4] Add ephemeralWebSession as an option to openAuth --- README.md | 2 ++ index.js | 9 +++++++-- ios/RNInAppBrowser.m | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4fdccbd..a32642a 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ Property | Description `modalTransitionStyle` (String) | The transition style to use when presenting the view controller. [`coverVertical`/`flipHorizontal`/`crossDissolve`/`partialCurl`] `modalEnabled` (Boolean) | Present the **SafariViewController** modally or as push instead. [`true`/`false`] `enableBarCollapsing` (Boolean) | Determines whether the browser's tool bars will collapse or not. [`true`/`false`] +`ephemeralWebSession` (Boolean) | Prevent re-use cookies of previous session (openAuth only) [`true`/`false`] ### Android Options Property | Description @@ -296,6 +297,7 @@ import { getDeepLink } from './utilities' InAppBrowser.openAuth(url, deepLink, { // iOS Properties dismissButtonStyle: 'cancel', + ephemeralWebSession: false, // Android Properties showTitle: false, enableUrlBarHiding: true, diff --git a/index.js b/index.js index f0fe0e9..08537d8 100644 --- a/index.js +++ b/index.js @@ -103,10 +103,15 @@ async function openAuth( redirectUrl: string, options: InAppBrowserOptions = {} ): Promise { + const inAppBrowserOptions = { + ...options, + animated: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false, + }; + if (_authSessionIsNativelySupported()) { - return RNInAppBrowser.openAuth(url, redirectUrl); + return RNInAppBrowser.openAuth(url, redirectUrl, inAppBrowserOptions); } else { - return _openAuthSessionPolyfillAsync(url, redirectUrl, options); + return _openAuthSessionPolyfillAsync(url, redirectUrl, inAppBrowserOptions); } } diff --git a/ios/RNInAppBrowser.m b/ios/RNInAppBrowser.m index d7aa754..0e93d1f 100644 --- a/ios/RNInAppBrowser.m +++ b/ios/RNInAppBrowser.m @@ -59,6 +59,7 @@ + (BOOL)requiresMainQueueSetup RCT_EXPORT_METHOD(openAuth:(NSString *)authURL redirectURL:(NSString *)redirectURL + options:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { @@ -66,6 +67,8 @@ + (BOOL)requiresMainQueueSetup return; } + BOOL ephemeralWebSession = [options[@"ephemeralWebSession"] boolValue]; + if (@available(iOS 11, *)) { NSURL *url = [[NSURL alloc] initWithString: authURL]; __weak typeof(self) weakSelf = self; @@ -93,7 +96,8 @@ + (BOOL)requiresMainQueueSetup callbackURLScheme:redirectURL completionHandler:completionHandler]; - if (@available(iOS 13.0, *)) { + if (@available(iOS 13.0, *) && ephemeralWebSession) { + //Prevent re-use cookie from last auth session webAuthSession.prefersEphemeralWebBrowserSession = true; } } else { From 510a1789380842505d4201b1e1bca016535cfcf7 Mon Sep 17 00:00:00 2001 From: Alexis Venner Date: Wed, 19 Feb 2020 14:53:03 +0100 Subject: [PATCH 3/4] Update index.js Fix property name --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 08537d8..37c22e7 100644 --- a/index.js +++ b/index.js @@ -105,7 +105,7 @@ async function openAuth( ): Promise { const inAppBrowserOptions = { ...options, - animated: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false, + ephemeralWebSession: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false, }; if (_authSessionIsNativelySupported()) { From 372500494c69adcb8caa5801d089d3c2130bd5c6 Mon Sep 17 00:00:00 2001 From: avenner Date: Wed, 19 Feb 2020 19:49:19 +0100 Subject: [PATCH 4/4] Add ephemeralWebSession in options object declaration --- index.d.ts | 3 ++- index.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4354696..9f486b2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -35,7 +35,8 @@ declare module 'react-native-inappbrowser-reborn' { | 'crossDissolve' | 'partialCurl', modalEnabled?: boolean, - enableBarCollapsing?: boolean + enableBarCollapsing?: boolean, + ephemeralWebSession?: boolean } type InAppBrowserAndroidOptions = { diff --git a/index.js b/index.js index 37c22e7..af5477e 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,8 @@ type InAppBrowseriOSOptions = { | 'crossDissolve' | 'partialCurl', modalEnabled?: boolean, - enableBarCollapsing?: boolean + enableBarCollapsing?: boolean, + ephemeralWebSession?: boolean }; type InAppBrowserAndroidOptions = {