Skip to content

Commit

Permalink
fix: Added androidTrustedWebActivity config to opt-in to EXTRA_LAUC…
Browse files Browse the repository at this point in the history
…H_AS_TRUSTED_WEB_ACTIVITY (#908)

* fix: Added `androidTrustedWebActivity` config to opt-in to EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY

* lint
  • Loading branch information
robwalkerco authored Oct 2, 2023
1 parent 33f9d90 commit 98a3f03
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
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

0 comments on commit 98a3f03

Please sign in to comment.