Skip to content

Commit 6db3c61

Browse files
committed
Add ephemeralWebSession as an option to openAuth
1 parent 9c0a550 commit 6db3c61

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
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.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ declare module 'react-native-inappbrowser-reborn' {
3535
| 'crossDissolve'
3636
| 'partialCurl',
3737
modalEnabled?: boolean,
38-
enableBarCollapsing?: boolean
38+
enableBarCollapsing?: boolean,
39+
ephemeralWebSession?: boolean,
3940
}
4041

4142
type InAppBrowserAndroidOptions = {

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ type InAppBrowseriOSOptions = {
4848
| 'crossDissolve'
4949
| 'partialCurl',
5050
modalEnabled?: boolean,
51-
enableBarCollapsing?: boolean
51+
enableBarCollapsing?: boolean,
52+
ephemeralWebSession?: boolean,
5253
};
5354

5455
type InAppBrowserAndroidOptions = {
@@ -103,10 +104,15 @@ async function openAuth(
103104
redirectUrl: string,
104105
options: InAppBrowserOptions = {}
105106
): Promise<AuthSessionResult> {
107+
const inAppBrowserOptions = {
108+
...options,
109+
animated: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false,
110+
};
111+
106112
if (_authSessionIsNativelySupported()) {
107-
return RNInAppBrowser.openAuth(url, redirectUrl);
113+
return RNInAppBrowser.openAuth(url, redirectUrl, inAppBrowserOptions);
108114
} else {
109-
return _openAuthSessionPolyfillAsync(url, redirectUrl, options);
115+
return _openAuthSessionPolyfillAsync(url, redirectUrl, inAppBrowserOptions);
110116
}
111117
}
112118

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)