Skip to content

Commit 98a3f03

Browse files
authored
fix: Added androidTrustedWebActivity config to opt-in to EXTRA_LAUCH_AS_TRUSTED_WEB_ACTIVITY (#908)
* fix: Added `androidTrustedWebActivity` config to opt-in to EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY * lint
1 parent 33f9d90 commit 98a3f03

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

.changeset/two-rice-collect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-app-auth': minor
3+
---
4+
5+
Added `androidTrustedWebActivity` config to opt-in to EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ with optional overrides.
141141
- **iosCustomBrowser** - (`string`) (default: undefined) _IOS_ override the used browser for authorization, used to open an external browser. If no value is provided, the `SFAuthenticationSession` or `SFSafariViewController` are used.
142142
- **iosPrefersEphemeralSession** - (`boolean`) (default: `false`) _IOS_ indicates whether the session should ask the browser for a private authentication session.
143143
- **androidAllowCustomBrowsers** - (`string[]`) (default: undefined) _ANDROID_ override the used browser for authorization. If no value is provided, all browsers are allowed.
144+
- **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.
144145
- **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.
145146

146147
#### result

android/src/main/java/com/rnappauth/RNAppAuthModule.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public void authorize(
240240
final boolean dangerouslyAllowInsecureHttpRequests,
241241
final ReadableMap customHeaders,
242242
final ReadableArray androidAllowCustomBrowsers,
243+
final boolean androidTrustedWebActivity,
243244
final Promise promise
244245
) {
245246
this.parseHeaderMap(customHeaders);
@@ -269,7 +270,8 @@ public void authorize(
269270
redirectUrl,
270271
useNonce,
271272
usePKCE,
272-
additionalParametersMap
273+
additionalParametersMap,
274+
androidTrustedWebActivity
273275
);
274276
} catch (ActivityNotFoundException e) {
275277
promise.reject("browser_not_found", e.getMessage());
@@ -300,7 +302,8 @@ public void onFetchConfigurationCompleted(
300302
redirectUrl,
301303
useNonce,
302304
usePKCE,
303-
additionalParametersMap
305+
additionalParametersMap,
306+
androidTrustedWebActivity
304307
);
305308
} catch (ActivityNotFoundException e) {
306309
promise.reject("browser_not_found", e.getMessage());
@@ -642,7 +645,8 @@ private void authorizeWithConfiguration(
642645
final String redirectUrl,
643646
final Boolean useNonce,
644647
final Boolean usePKCE,
645-
final Map<String, String> additionalParametersMap
648+
final Map<String, String> additionalParametersMap,
649+
final Boolean androidTrustedWebActivity
646650
) {
647651

648652
String scopesString = null;
@@ -717,7 +721,10 @@ private void authorizeWithConfiguration(
717721

718722
CustomTabsIntent.Builder intentBuilder = authService.createCustomTabsIntentBuilder();
719723
CustomTabsIntent customTabsIntent = intentBuilder.build();
720-
customTabsIntent.intent.putExtra(TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true);
724+
725+
if (androidTrustedWebActivity) {
726+
customTabsIntent.intent.putExtra(TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true);
727+
}
721728

722729
Intent authIntent = authService.getAuthorizationRequestIntent(authRequest, customTabsIntent);
723730

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type AuthConfiguration = BaseAuthConfiguration & {
8888
| 'samsung'
8989
| 'samsungCustomTab'
9090
)[];
91+
androidTrustedWebActivity?: boolean;
9192
iosPrefersEphemeralSession?: boolean;
9293
};
9394

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export const authorize = ({
209209
skipCodeExchange = false,
210210
iosCustomBrowser = null,
211211
androidAllowCustomBrowsers = null,
212+
androidTrustedWebActivity = false,
212213
connectionTimeoutSeconds,
213214
iosPrefersEphemeralSession = false,
214215
}) => {
@@ -239,6 +240,7 @@ export const authorize = ({
239240
nativeMethodArguments.push(dangerouslyAllowInsecureHttpRequests);
240241
nativeMethodArguments.push(customHeaders);
241242
nativeMethodArguments.push(androidAllowCustomBrowsers);
243+
nativeMethodArguments.push(androidTrustedWebActivity);
242244
}
243245

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

index.spec.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('AppAuth', () => {
6363
iosCustomBrowser: 'safari',
6464
iosPrefersEphemeralSession: true,
6565
androidAllowCustomBrowsers: ['chrome'],
66+
androidTrustedWebActivity: false,
6667
};
6768

6869
const registerConfig = {
@@ -738,7 +739,8 @@ describe('AppAuth', () => {
738739
config.clientAuthMethod,
739740
false,
740741
config.customHeaders,
741-
config.androidAllowCustomBrowsers
742+
config.androidAllowCustomBrowsers,
743+
config.androidTrustedWebActivity
742744
);
743745
});
744746
});
@@ -761,7 +763,8 @@ describe('AppAuth', () => {
761763
config.clientAuthMethod,
762764
false,
763765
config.customHeaders,
764-
config.androidAllowCustomBrowsers
766+
config.androidAllowCustomBrowsers,
767+
config.androidTrustedWebActivity
765768
);
766769
});
767770

@@ -782,7 +785,8 @@ describe('AppAuth', () => {
782785
config.clientAuthMethod,
783786
false,
784787
config.customHeaders,
785-
config.androidAllowCustomBrowsers
788+
config.androidAllowCustomBrowsers,
789+
config.androidTrustedWebActivity
786790
);
787791
});
788792

@@ -803,7 +807,8 @@ describe('AppAuth', () => {
803807
config.clientAuthMethod,
804808
true,
805809
config.customHeaders,
806-
config.androidAllowCustomBrowsers
810+
config.androidAllowCustomBrowsers,
811+
config.androidTrustedWebActivity
807812
);
808813
});
809814
});
@@ -833,7 +838,8 @@ describe('AppAuth', () => {
833838
config.clientAuthMethod,
834839
false,
835840
customHeaders,
836-
config.androidAllowCustomBrowsers
841+
config.androidAllowCustomBrowsers,
842+
config.androidTrustedWebActivity
837843
);
838844
});
839845
});

0 commit comments

Comments
 (0)