Skip to content

Commit 724e76f

Browse files
committed
Add ephemeralWebSession as an option to openAuth
1 parent f0c28d0 commit 724e76f

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Property | Description
144144
`modalTransitionStyle` (String) | The transition style to use when presenting the view controller. [`coverVertical`/`flipHorizontal`/`crossDissolve`/`partialCurl`]
145145
`modalEnabled` (Boolean) | Present the **SafariViewController** modally or as push instead. [`true`/`false`]
146146
`enableBarCollapsing` (Boolean) | Determines whether the browser's tool bars will collapse or not. [`true`/`false`]
147+
`ephemeralWebSession` (Boolean) | Prevent re-use cookies of previous session (openAuth only) [`true`/`false`]
147148
148149
### Android Options
149150
Property | Description
@@ -296,6 +297,7 @@ import { getDeepLink } from './utilities'
296297
InAppBrowser.openAuth(url, deepLink, {
297298
// iOS Properties
298299
dismissButtonStyle: 'cancel',
300+
ephemeralWebSession: false,
299301
// Android Properties
300302
showTitle: false,
301303
enableUrlBarHiding: true,

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ async function openAuth(
103103
redirectUrl: string,
104104
options: InAppBrowserOptions = {}
105105
): Promise<AuthSessionResult> {
106+
const inAppBrowserOptions = {
107+
...options,
108+
animated: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false,
109+
};
110+
106111
if (_authSessionIsNativelySupported()) {
107-
return RNInAppBrowser.openAuth(url, redirectUrl);
112+
return RNInAppBrowser.openAuth(url, redirectUrl, inAppBrowserOptions);
108113
} else {
109-
return _openAuthSessionPolyfillAsync(url, redirectUrl, options);
114+
return _openAuthSessionPolyfillAsync(url, redirectUrl, inAppBrowserOptions);
110115
}
111116
}
112117

ios/RNInAppBrowser.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@ + (BOOL)requiresMainQueueSetup
5959

6060
RCT_EXPORT_METHOD(openAuth:(NSString *)authURL
6161
redirectURL:(NSString *)redirectURL
62+
options:(NSDictionary *)options
6263
resolver:(RCTPromiseResolveBlock)resolve
6364
rejecter:(RCTPromiseRejectBlock)reject)
6465
{
6566
if (![self initializeWebBrowserWithResolver:resolve andRejecter:reject]) {
6667
return;
6768
}
6869

70+
BOOL ephemeralWebSession = [options[@"ephemeralWebSession"] boolValue];
71+
6972
if (@available(iOS 11, *)) {
7073
NSURL *url = [[NSURL alloc] initWithString: authURL];
7174
__weak typeof(self) weakSelf = self;
@@ -93,7 +96,8 @@ + (BOOL)requiresMainQueueSetup
9396
callbackURLScheme:redirectURL
9497
completionHandler:completionHandler];
9598

96-
if (@available(iOS 13.0, *)) {
99+
if (@available(iOS 13.0, *) && ephemeralWebSession) {
100+
//Prevent re-use cookie from last auth session
97101
webAuthSession.prefersEphemeralWebBrowserSession = true;
98102
}
99103
} else {

0 commit comments

Comments
 (0)