Sharing token between apps on Android/IOS

3 weeks ago 28
ARTICLE AD BOX

I need to share tokens between two apps from the same author. In App 1, the user logs in and receives a refresh_token and an access_token. App 1 is a legacy app written in Cordova, and App 2 is written in React Native.

What I need is: when a user logs into App 1, the app saves the tokens in a shared folder (for example). When the same user opens App 2, it checks if those tokens exist. If they do, App 2 will use the refresh_token to get a new access_token if the current one is invalid.

what I already tried:

External Libraries: I evaluated existing libraries like react-native-shared-group-preferences, but they rely on External Storage (public folders) for Android. This is a security risk for authentication tokens and is deprecated in modern Android versions (SDK 30+).

Encryption Standards: I initially faced issues with token decryption because Cordova and React Native use different default encryption transformations. I had to manually override the React Native implementation to use RSA/ECB/PKCS1Padding so the legacy Cordova Java code could successfully decrypt the data.

Plugin Maintenance: I found that most Cordova KeyStore plugins haven't been updated in over 6 years. I had to manually patch the Java code to support the sharedUserId context, which means we will need to maintain a local fork of the plugin during this migration period.

Native Bridge: I concluded that a custom Native Module in React Native is the only reliable way to use createPackageContext to securely access the Cordova SharedPreferences without exposing data to the rest of the OS."

At this moment, I can read tokens on Cordova from React Native, But I can't read on React Native from Cordova.

Read Entire Article