Skip to content

Commit

Permalink
Merge pull request #141 from avenner/patch-1
Browse files Browse the repository at this point in the history
Supports ephemeralWebBrowserSession on iOS 13
  • Loading branch information
jdnichollsc authored Feb 19, 2020
2 parents 283e943 + 3725004 commit 4c0ed7c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -296,6 +297,7 @@ import { getDeepLink } from './utilities'
InAppBrowser.openAuth(url, deepLink, {
// iOS Properties
dismissButtonStyle: 'cancel',
ephemeralWebSession: false,
// Android Properties
showTitle: false,
enableUrlBarHiding: true,
Expand Down
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ declare module 'react-native-inappbrowser-reborn' {
| 'crossDissolve'
| 'partialCurl',
modalEnabled?: boolean,
enableBarCollapsing?: boolean
enableBarCollapsing?: boolean,
ephemeralWebSession?: boolean
}

type InAppBrowserAndroidOptions = {
Expand Down
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type InAppBrowseriOSOptions = {
| 'crossDissolve'
| 'partialCurl',
modalEnabled?: boolean,
enableBarCollapsing?: boolean
enableBarCollapsing?: boolean,
ephemeralWebSession?: boolean
};

type InAppBrowserAndroidOptions = {
Expand Down Expand Up @@ -103,10 +104,15 @@ async function openAuth(
redirectUrl: string,
options: InAppBrowserOptions = {}
): Promise<AuthSessionResult> {
const inAppBrowserOptions = {
...options,
ephemeralWebSession: 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);
}
}

Expand Down
8 changes: 8 additions & 0 deletions ios/RNInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ + (BOOL)requiresMainQueueSetup

RCT_EXPORT_METHOD(openAuth:(NSString *)authURL
redirectURL:(NSString *)redirectURL
options:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
if (![self initializeWebBrowserWithResolver:resolve andRejecter:reject]) {
return;
}

BOOL ephemeralWebSession = [options[@"ephemeralWebSession"] boolValue];

if (@available(iOS 11, *)) {
NSURL *url = [[NSURL alloc] initWithString: authURL];
__weak typeof(self) weakSelf = self;
Expand All @@ -92,6 +95,11 @@ + (BOOL)requiresMainQueueSetup
initWithURL:url
callbackURLScheme:redirectURL
completionHandler:completionHandler];

if (@available(iOS 13.0, *) && ephemeralWebSession) {
//Prevent re-use cookie from last auth session
webAuthSession.prefersEphemeralWebBrowserSession = true;
}
} else {
authSession = [[SFAuthenticationSession alloc]
initWithURL:url
Expand Down

0 comments on commit 4c0ed7c

Please sign in to comment.