Skip to content

Commit aba0370

Browse files
feat: add epehemral to android
1 parent f1cfb3c commit aba0370

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

docs/docs/usage/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ See specific example [configurations for your provider](/docs/category/providers
4848
- **skipCodeExchange** - (`boolean`) (default: false) just return the authorization response, instead of automatically exchanging the authorization code. This is useful if this exchange needs to be done manually (not client-side)
4949
- **iosCustomBrowser** - (`string`) (default: undefined) _IOS_ override the used browser for authorization, used to open an external browser. If no value is provided, the `ASWebAuthenticationSession` or `SFSafariViewController` are used by the `AppAuth-iOS` library.
5050
- **iosPrefersEphemeralSession** - (`boolean`) (default: `false`) _IOS_ indicates whether the session should ask the browser for a private authentication session.
51+
-**androidPrefersEphemeralSession** - (`boolean`) (default: `false`) _ANDROID_ indicates whether the session should ask the browser for a private authentication session.
5152
- **androidAllowCustomBrowsers** - (`string[]`) (default: undefined) _ANDROID_ override the used browser for authorization. If no value is provided, all browsers are allowed.
5253
- **androidTrustedWebActivity** - (`boolean`) (default: `false`) _ANDROID_ Use [`EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY`](https://developer.chrome.com/docs/android/trusted-web-activity/) when opening web view.
5354
- **connectionTimeoutSeconds** - (`number`) configure the request timeout interval in seconds. This must be a positive number. The default values are 60 seconds on iOS and 15 seconds on Android.

packages/react-native-app-auth/android/src/main/java/com/rnappauth/RNAppAuthModule.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public void authorize(
243243
final ReadableMap customHeaders,
244244
final ReadableArray androidAllowCustomBrowsers,
245245
final boolean androidTrustedWebActivity,
246+
final boolean androidPrefersEphemeralSession,
246247
final Promise promise) {
247248
this.parseHeaderMap(customHeaders);
248249
final ConnectionBuilder builder = createConnectionBuilder(dangerouslyAllowInsecureHttpRequests,
@@ -277,7 +278,8 @@ public void authorize(
277278
useNonce,
278279
usePKCE,
279280
additionalParametersMap,
280-
androidTrustedWebActivity);
281+
androidTrustedWebActivity,
282+
androidPrefersEphemeralSession);
281283
} catch (ActivityNotFoundException e) {
282284
promise.reject("browser_not_found", e.getMessage());
283285
} catch (Exception e) {
@@ -308,7 +310,8 @@ public void onFetchConfigurationCompleted(
308310
useNonce,
309311
usePKCE,
310312
additionalParametersMap,
311-
androidTrustedWebActivity);
313+
androidTrustedWebActivity,
314+
androidPrefersEphemeralSession);
312315
} catch (ActivityNotFoundException e) {
313316
promise.reject("browser_not_found", e.getMessage());
314317
} catch (Exception e) {
@@ -660,7 +663,8 @@ private void authorizeWithConfiguration(
660663
final Boolean useNonce,
661664
final Boolean usePKCE,
662665
final Map<String, String> additionalParametersMap,
663-
final Boolean androidTrustedWebActivity) {
666+
final Boolean androidTrustedWebActivity,
667+
final Boolean androidPrefersEphemeralSession) {
664668

665669
String scopesString = null;
666670

@@ -731,8 +735,8 @@ private void authorizeWithConfiguration(
731735
AuthorizationService authService = new AuthorizationService(context, appAuthConfiguration);
732736

733737
CustomTabsIntent.Builder intentBuilder = authService.createCustomTabsIntentBuilder();
734-
CustomTabsIntent customTabsIntent = intentBuilder.build();
735-
738+
CustomTabsIntent customTabsIntent = intentBuilder.setEphemeralBrowsingEnabled(androidPrefersEphemeralSession).build();
739+
736740
if (androidTrustedWebActivity) {
737741
customTabsIntent.intent.putExtra(TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true);
738742
}

packages/react-native-app-auth/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export type AuthConfiguration = BaseAuthConfiguration & {
8989
| 'samsungCustomTab'
9090
)[];
9191
androidTrustedWebActivity?: boolean;
92+
androidPrefersEphemeralSession?: boolean;
9293
iosPrefersEphemeralSession?: boolean;
9394
};
9495

packages/react-native-app-auth/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export const authorize = ({
214214
androidTrustedWebActivity = false,
215215
connectionTimeoutSeconds,
216216
iosPrefersEphemeralSession = false,
217+
androidPrefersEphemeralSession = false
217218
}) => {
218219
validateIssuerOrServiceConfigurationEndpoints(issuer, serviceConfiguration);
219220
validateClientId(clientId);
@@ -243,6 +244,7 @@ export const authorize = ({
243244
nativeMethodArguments.push(customHeaders);
244245
nativeMethodArguments.push(androidAllowCustomBrowsers);
245246
nativeMethodArguments.push(androidTrustedWebActivity);
247+
nativeMethodArguments.push(androidPrefersEphemeralSession);
246248
}
247249

248250
if (Platform.OS === 'ios') {

0 commit comments

Comments
 (0)