Skip to content

Commit

Permalink
feat: [IOCOM-1936] Handling of InApp Browser opening failure for FIMS…
Browse files Browse the repository at this point in the history
… SSO (#6450)

## Short description
This PR adds the handling of the InApp Browser opening failure for the
FIMS Authentication flow.

|iOS|Android|
|-|-|

|![iOS](https://github.com/user-attachments/assets/8da74aaf-0c5e-4ab8-b2f9-32a4a3dafb20)|![Android](https://github.com/user-attachments/assets/28d2e473-fc5d-4fea-8fc3-007e83b0e544)|

## List of changes proposed in this pull request
- InApp Browser opening call has been wrapped in a try catch in order to
catch the error, track it and warn the user with a Toast.
- `login-utils` library to latest version (where errors are sent back to
react-native with the same format between Android and iOS)
- in-app `isLoginUtilsError` utility replaced with `the login-utils` one

## How to test
Using the io-dev-api-server, edit the native code to reject the promise
(following a standard error generation) and check that the error is
properly tracked and displayed.
  • Loading branch information
Vangaorth authored Nov 26, 2024
1 parent 9d8f0e1 commit 785882d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ PODS:
- JOSESwift (~> 2.3)
- RCT-Folly (= 2021.07.22.00)
- React-Core
- pagopa-io-react-native-login-utils (1.0.6):
- pagopa-io-react-native-login-utils (1.0.7):
- React-Core
- pagopa-react-native-zendesk (0.3.29):
- RCT-Folly (= 2021.07.22.00)
Expand Down Expand Up @@ -1063,7 +1063,7 @@ SPEC CHECKSUMS:
pagopa-io-react-native-http-client: cbdfb83c92432efb0de22b7c3c85cffa391870f8
pagopa-io-react-native-integrity: ca77804cefb1cd75d04053652472bcb938ce4b18
pagopa-io-react-native-jwt: 27f6cb1ea58ea1df6778c67f23a932b90dc7e9a2
pagopa-io-react-native-login-utils: a445c97d7d7dc86b089079029a1340f4c682128c
pagopa-io-react-native-login-utils: 6ba1c399fda70e9f92a29244bea33b22958869af
pagopa-react-native-zendesk: 60a26f8a8072234789c34bb7c8a769c156eb57dc
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: 264adaca1d8b1a9c078761891898d4142df05313
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"@pagopa/io-react-native-http-client": "1.0.5",
"@pagopa/io-react-native-integrity": "^0.3.0",
"@pagopa/io-react-native-jwt": "^1.3.0",
"@pagopa/io-react-native-login-utils": "1.0.6",
"@pagopa/io-react-native-login-utils": "^1.0.7",
"@pagopa/io-react-native-wallet": "^0.24.1",
"@pagopa/io-react-native-zendesk": "^0.3.29",
"@pagopa/react-native-cie": "^1.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
isCancelledFailure,
nativeRequest
} from "@pagopa/io-react-native-http-client";
import { openAuthenticationSession } from "@pagopa/io-react-native-login-utils";
import {
isLoginUtilsError,
openAuthenticationSession
} from "@pagopa/io-react-native-login-utils";
import * as E from "fp-ts/lib/Either";
import { Parser as HTMLParser2 } from "htmlparser2";
import {
Expand All @@ -15,6 +18,7 @@ import {
} from "react-native-url-polyfill";
import { call, put, select } from "typed-redux-saga/macro";
import { ActionType } from "typesafe-actions";
import { IOToast } from "@pagopa/io-app-design-system";
import { fimsDomainSelector } from "../../../../store/reducers/backendStatus/remoteConfig";
import { ReduxSagaEffect } from "../../../../types/utils";
import { LollipopConfig } from "../../../lollipop";
Expand All @@ -28,6 +32,7 @@ import { fimsGetRedirectUrlAndOpenIABAction } from "../store/actions";
import { serviceByIdSelector } from "../../../services/details/store/reducers";
import { fimsCtaTextSelector } from "../store/selectors";
import { trackInAppBrowserOpening } from "../../common/analytics";
import I18n from "../../../../i18n";
import {
deallocateFimsAndRenewFastLoginSession,
deallocateFimsResourcesAndNavigateBack
Expand Down Expand Up @@ -146,10 +151,7 @@ export function* handleFimsGetRedirectUrlAndOpenIAB(
try {
yield* call(openAuthenticationSession, inAppBrowserRedirectUrl, "", true);
} catch (error: unknown) {
// At the time of writing, openAuthenticationSession returns
// different kind of structures for error's instances so we
// are not able to distinguish between normal closing of the
// InApp Browser on both systems and other kind of errors.
yield* call(handleInAppBrowserErrorIfNeeded, error);
}
}

Expand Down Expand Up @@ -488,3 +490,24 @@ function* computeAndTrackInAppBrowserOpening(
ctaText
);
}

function* handleInAppBrowserErrorIfNeeded(error: unknown) {
if (!isInAppBrowserClosedError(error)) {
const debugMessage = `IAB opening failed: ${inAppBrowserErrorToHumanReadable(
error
)}`;
yield* call(computeAndTrackAuthenticationError, debugMessage);
yield* call(IOToast.error, I18n.t("FIMS.consentsScreen.inAppBrowserError"));
}
}

const isInAppBrowserClosedError = (error: unknown) =>
isLoginUtilsError(error) &&
error.userInfo.error === "NativeAuthSessionClosed";

const inAppBrowserErrorToHumanReadable = (error: unknown) => {
if (isLoginUtilsError(error)) {
return `${error.code} ${error.userInfo.error}`;
}
return JSON.stringify(error);
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jest.mock("@pagopa/io-react-native-login-utils", () => ({
Parameter: undefined
},
code: "409"
})
}),
isLoginUtilsError: (e: unknown) =>
(e as LoginUtilsError).userInfo !== undefined
}));

describe("Lollipop regenerate key, get redirects and verification", () => {
Expand Down
7 changes: 2 additions & 5 deletions ts/features/lollipop/utils/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as E from "fp-ts/lib/Either";
import * as TE from "fp-ts/lib/TaskEither";
import { parseStringPromise } from "xml2js";
import {
LoginUtilsError,
getRedirects
getRedirects,
isLoginUtilsError
} from "@pagopa/io-react-native-login-utils";
import URLParse from "url-parse";
import { PublicKey } from "@pagopa/io-react-native-crypto";
Expand Down Expand Up @@ -95,9 +95,6 @@ export const verifyLollipopSamlRequestTask = (
);
});

export const isLoginUtilsError = (error: unknown): error is LoginUtilsError =>
(error as LoginUtilsError).userInfo !== undefined;

export const regenerateKeyGetRedirectsAndVerifySaml = (
loginUri: string,
keyTag: string,
Expand Down
6 changes: 4 additions & 2 deletions ts/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { pipe } from "fp-ts/lib/function";
import * as B from "fp-ts/lib/boolean";
import { LoginUtilsError } from "@pagopa/io-react-native-login-utils";
import {
isLoginUtilsError,
LoginUtilsError
} from "@pagopa/io-react-native-login-utils";
import {
WebViewErrorEvent,
WebViewHttpErrorEvent
Expand All @@ -9,7 +12,6 @@ import URLParse from "url-parse";
import EUCOVIDCERT_ROUTES from "../features/euCovidCert/navigation/routes";
import { euCovidCertificateEnabled } from "../config";
import { mixpanelTrack } from "../mixpanel";
import { isLoginUtilsError } from "../features/lollipop/utils/login";
import {
clearKeychainError,
getKeychainError,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2272,10 +2272,10 @@
js-base64 "^3.7.7"
zod "^3.22.4"

"@pagopa/[email protected].6":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@pagopa/io-react-native-login-utils/-/io-react-native-login-utils-1.0.6.tgz#b211e953eb05b76b43effc0d9d7be79767c361f9"
integrity sha512-Dx1WPdqFaB76Wv8WgkLCIQoj9ADZeWyfe/GTnGWQKeIWnTe5v3socbEDdax9fh0asxizuTVzTVj962H2nCQxwg==
"@pagopa/io-react-native-login-utils@^1.0.7":
version "1.0.7"
resolved "https://registry.yarnpkg.com/@pagopa/io-react-native-login-utils/-/io-react-native-login-utils-1.0.7.tgz#b92f9e04e15f724743367ff1bfd33a9ceddcd308"
integrity sha512-+I8uT3w/4XkuPC4+Gmy/6LvR3CpUpjjHL6B4qgZQ15EVHtfI97zo3blC4ETPpWdx1T8e37AKu9ZEJIHjOexm/w==

"@pagopa/io-react-native-wallet@^0.24.1":
version "0.24.1"
Expand Down

0 comments on commit 785882d

Please sign in to comment.