Skip to content

Commit 38152f7

Browse files
feat: ephemeral session on android (#1100)
Co-authored-by: bryceknz <25199713+bryceknz@users.noreply.github.com>
1 parent 878cfeb commit 38152f7

8 files changed

Lines changed: 37 additions & 16 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'react-native-app-auth': minor
3+
---
4+
5+
Add `androidPrefersEphemeralSession` to request ephemeral Custom Tabs on Android when supported.
6+
7+
This also updates AndroidX Browser to 1.9.0, so Android projects now need min SDK 21+, compile SDK 36+, and Android Gradle Plugin 8.9.1+.

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 when supported.
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.

examples/demo/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ buildscript {
22
ext {
33
buildToolsVersion = "35.0.0"
44
minSdkVersion = 24
5-
compileSdkVersion = 35
5+
compileSdkVersion = 36
66
targetSdkVersion = 35
77
ndkVersion = "27.1.12297006"
88
kotlinVersion = "2.0.21"
@@ -12,7 +12,7 @@ buildscript {
1212
mavenCentral()
1313
}
1414
dependencies {
15-
classpath("com.android.tools.build:gradle")
15+
classpath("com.android.tools.build:gradle:8.9.1")
1616
classpath("com.facebook.react:react-native-gradle-plugin")
1717
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
1818
}

packages/react-native-app-auth/android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212
google()
1313
}
1414
dependencies {
15-
classpath 'com.android.tools.build:gradle:8.5.2'
15+
classpath 'com.android.tools.build:gradle:8.9.1'
1616
}
1717
}
1818
}
@@ -25,9 +25,9 @@ android {
2525
namespace "com.rnappauth"
2626
}
2727

28-
compileSdkVersion safeExtGet('compileSdkVersion', 34)
28+
compileSdkVersion safeExtGet('compileSdkVersion', 36)
2929
defaultConfig {
30-
minSdkVersion safeExtGet('minSdkVersion', 16)
30+
minSdkVersion safeExtGet('minSdkVersion', 21)
3131
targetSdkVersion safeExtGet('targetSdkVersion', 34)
3232
versionCode 1
3333
versionName "1.0"
@@ -62,5 +62,5 @@ dependencies {
6262
//noinspection GradleDynamicVersion
6363
implementation 'com.facebook.react:react-native:+' // From node_modules
6464
implementation 'net.openid:appauth:0.11.1'
65-
implementation 'androidx.browser:browser:1.4.0'
65+
implementation 'androidx.browser:browser:1.9.0'
6666
}

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
@@ -244,6 +244,7 @@ public void authorize(
244244
final ReadableMap customHeaders,
245245
final ReadableArray androidAllowCustomBrowsers,
246246
final boolean androidTrustedWebActivity,
247+
final boolean androidPrefersEphemeralSession,
247248
final Promise promise) {
248249
this.parseHeaderMap(customHeaders);
249250
final ConnectionBuilder builder = createConnectionBuilder(dangerouslyAllowInsecureHttpRequests,
@@ -278,7 +279,8 @@ public void authorize(
278279
useNonce,
279280
usePKCE,
280281
additionalParametersMap,
281-
androidTrustedWebActivity);
282+
androidTrustedWebActivity,
283+
androidPrefersEphemeralSession);
282284
} catch (ActivityNotFoundException e) {
283285
promise.reject("browser_not_found", e.getMessage());
284286
} catch (Exception e) {
@@ -309,7 +311,8 @@ public void onFetchConfigurationCompleted(
309311
useNonce,
310312
usePKCE,
311313
additionalParametersMap,
312-
androidTrustedWebActivity);
314+
androidTrustedWebActivity,
315+
androidPrefersEphemeralSession);
313316
} catch (ActivityNotFoundException e) {
314317
promise.reject("browser_not_found", e.getMessage());
315318
} catch (Exception e) {
@@ -661,7 +664,8 @@ private void authorizeWithConfiguration(
661664
final Boolean useNonce,
662665
final Boolean usePKCE,
663666
final Map<String, String> additionalParametersMap,
664-
final Boolean androidTrustedWebActivity) {
667+
final Boolean androidTrustedWebActivity,
668+
final Boolean androidPrefersEphemeralSession) {
665669

666670
String scopesString = null;
667671

@@ -736,8 +740,8 @@ private void authorizeWithConfiguration(
736740
AuthorizationService authService = new AuthorizationService(context, appAuthConfiguration);
737741

738742
CustomTabsIntent.Builder intentBuilder = authService.createCustomTabsIntentBuilder();
739-
CustomTabsIntent customTabsIntent = intentBuilder.build();
740-
743+
CustomTabsIntent customTabsIntent = intentBuilder.setEphemeralBrowsingEnabled(androidPrefersEphemeralSession).build();
744+
741745
if (androidTrustedWebActivity) {
742746
customTabsIntent.intent.putExtra(TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true);
743747
}

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
@@ -230,6 +230,7 @@ export const authorize = ({
230230
androidTrustedWebActivity = false,
231231
connectionTimeoutSeconds,
232232
iosPrefersEphemeralSession = false,
233+
androidPrefersEphemeralSession = false,
233234
}) => {
234235
validateIssuerOrServiceConfigurationEndpoints(issuer, serviceConfiguration);
235236
validateClientId(clientId);
@@ -259,6 +260,7 @@ export const authorize = ({
259260
nativeMethodArguments.push(customHeaders);
260261
nativeMethodArguments.push(androidAllowCustomBrowsers);
261262
nativeMethodArguments.push(androidTrustedWebActivity);
263+
nativeMethodArguments.push(androidPrefersEphemeralSession);
262264
}
263265

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

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('AppAuth', () => {
6969
iosPrefersEphemeralSession: true,
7070
androidAllowCustomBrowsers: ['chrome'],
7171
androidTrustedWebActivity: false,
72+
androidPrefersEphemeralSession: true,
7273
};
7374

7475
const registerConfig = {
@@ -758,7 +759,8 @@ describe('AppAuth', () => {
758759
false,
759760
config.customHeaders,
760761
config.androidAllowCustomBrowsers,
761-
config.androidTrustedWebActivity
762+
config.androidTrustedWebActivity,
763+
config.androidPrefersEphemeralSession
762764
);
763765
});
764766
});
@@ -782,7 +784,8 @@ describe('AppAuth', () => {
782784
false,
783785
config.customHeaders,
784786
config.androidAllowCustomBrowsers,
785-
config.androidTrustedWebActivity
787+
config.androidTrustedWebActivity,
788+
config.androidPrefersEphemeralSession
786789
);
787790
});
788791

@@ -804,7 +807,8 @@ describe('AppAuth', () => {
804807
false,
805808
config.customHeaders,
806809
config.androidAllowCustomBrowsers,
807-
config.androidTrustedWebActivity
810+
config.androidTrustedWebActivity,
811+
config.androidPrefersEphemeralSession
808812
);
809813
});
810814

@@ -826,7 +830,8 @@ describe('AppAuth', () => {
826830
true,
827831
config.customHeaders,
828832
config.androidAllowCustomBrowsers,
829-
config.androidTrustedWebActivity
833+
config.androidTrustedWebActivity,
834+
config.androidPrefersEphemeralSession
830835
);
831836
});
832837
});
@@ -857,7 +862,8 @@ describe('AppAuth', () => {
857862
false,
858863
customHeaders,
859864
config.androidAllowCustomBrowsers,
860-
config.androidTrustedWebActivity
865+
config.androidTrustedWebActivity,
866+
config.androidPrefersEphemeralSession
861867
);
862868
});
863869
});

0 commit comments

Comments
 (0)