Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports ephemeralWebBrowserSession on iOS 13 #141

Merged
merged 4 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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