Skip to content

fix: Added androidTrustedWebActivity config to opt-in to EXTRA_LAUCH_AS_TRUSTED_WEB_ACTIVITY #908

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

Merged
merged 2 commits into from
Oct 2, 2023
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
5 changes: 5 additions & 0 deletions .changeset/two-rice-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-app-auth': minor
---

Added `androidTrustedWebActivity` config to opt-in to EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ with optional overrides.
- **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.
- **iosPrefersEphemeralSession** - (`boolean`) (default: `false`) _IOS_ indicates whether the session should ask the browser for a private authentication session.
- **androidAllowCustomBrowsers** - (`string[]`) (default: undefined) _ANDROID_ override the used browser for authorization. If no value is provided, all browsers are allowed.
- **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.
- **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.

#### result
Expand Down
15 changes: 11 additions & 4 deletions android/src/main/java/com/rnappauth/RNAppAuthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void authorize(
final boolean dangerouslyAllowInsecureHttpRequests,
final ReadableMap customHeaders,
final ReadableArray androidAllowCustomBrowsers,
final boolean androidTrustedWebActivity,
final Promise promise
) {
this.parseHeaderMap(customHeaders);
Expand Down Expand Up @@ -269,7 +270,8 @@ public void authorize(
redirectUrl,
useNonce,
usePKCE,
additionalParametersMap
additionalParametersMap,
androidTrustedWebActivity
);
} catch (ActivityNotFoundException e) {
promise.reject("browser_not_found", e.getMessage());
Expand Down Expand Up @@ -300,7 +302,8 @@ public void onFetchConfigurationCompleted(
redirectUrl,
useNonce,
usePKCE,
additionalParametersMap
additionalParametersMap,
androidTrustedWebActivity
);
} catch (ActivityNotFoundException e) {
promise.reject("browser_not_found", e.getMessage());
Expand Down Expand Up @@ -642,7 +645,8 @@ private void authorizeWithConfiguration(
final String redirectUrl,
final Boolean useNonce,
final Boolean usePKCE,
final Map<String, String> additionalParametersMap
final Map<String, String> additionalParametersMap,
final Boolean androidTrustedWebActivity
) {

String scopesString = null;
Expand Down Expand Up @@ -717,7 +721,10 @@ private void authorizeWithConfiguration(

CustomTabsIntent.Builder intentBuilder = authService.createCustomTabsIntentBuilder();
CustomTabsIntent customTabsIntent = intentBuilder.build();
customTabsIntent.intent.putExtra(TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true);

if (androidTrustedWebActivity) {
customTabsIntent.intent.putExtra(TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true);
}

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

Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type AuthConfiguration = BaseAuthConfiguration & {
| 'samsung'
| 'samsungCustomTab'
)[];
androidTrustedWebActivity?: boolean;
iosPrefersEphemeralSession?: boolean;
};

Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const authorize = ({
skipCodeExchange = false,
iosCustomBrowser = null,
androidAllowCustomBrowsers = null,
androidTrustedWebActivity = false,
connectionTimeoutSeconds,
iosPrefersEphemeralSession = false,
}) => {
Expand Down Expand Up @@ -239,6 +240,7 @@ export const authorize = ({
nativeMethodArguments.push(dangerouslyAllowInsecureHttpRequests);
nativeMethodArguments.push(customHeaders);
nativeMethodArguments.push(androidAllowCustomBrowsers);
nativeMethodArguments.push(androidTrustedWebActivity);
}

if (Platform.OS === 'ios') {
Expand Down
16 changes: 11 additions & 5 deletions index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('AppAuth', () => {
iosCustomBrowser: 'safari',
iosPrefersEphemeralSession: true,
androidAllowCustomBrowsers: ['chrome'],
androidTrustedWebActivity: false,
};

const registerConfig = {
Expand Down Expand Up @@ -738,7 +739,8 @@ describe('AppAuth', () => {
config.clientAuthMethod,
false,
config.customHeaders,
config.androidAllowCustomBrowsers
config.androidAllowCustomBrowsers,
config.androidTrustedWebActivity
);
});
});
Expand All @@ -761,7 +763,8 @@ describe('AppAuth', () => {
config.clientAuthMethod,
false,
config.customHeaders,
config.androidAllowCustomBrowsers
config.androidAllowCustomBrowsers,
config.androidTrustedWebActivity
);
});

Expand All @@ -782,7 +785,8 @@ describe('AppAuth', () => {
config.clientAuthMethod,
false,
config.customHeaders,
config.androidAllowCustomBrowsers
config.androidAllowCustomBrowsers,
config.androidTrustedWebActivity
);
});

Expand All @@ -803,7 +807,8 @@ describe('AppAuth', () => {
config.clientAuthMethod,
true,
config.customHeaders,
config.androidAllowCustomBrowsers
config.androidAllowCustomBrowsers,
config.androidTrustedWebActivity
);
});
});
Expand Down Expand Up @@ -833,7 +838,8 @@ describe('AppAuth', () => {
config.clientAuthMethod,
false,
customHeaders,
config.androidAllowCustomBrowsers
config.androidAllowCustomBrowsers,
config.androidTrustedWebActivity
);
});
});
Expand Down