react-native-app-auth: authorize() returns error 'Data intent is null' on Android
Issue
Every time I call authorize() method I get Error: Data intent is null, whenever running on an Android emulator with ‘R’ operating system. Any idea what could be causing this error and how to fix it?
const config = {
warmAndPrefetchChrome: Platform.OS === 'android',
issuer,
clientId,
redirectUrl: 'testSchema://oauth/redirect',
scopes: ['openid', 'profile', 'api', 'offline_access'],
usePKCE: true,
};
export const authenticate = async () => {
try {
const result = await authorize(config);
console.log('authorized') // Execution never makes it to this line
return result
} catch (e) {
throw new Error(e);
}
};
In android/app/builde.gradle
defaultConfig {
applicationId "com.testApp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0.0"
resValue "string", "build_config_package", "com.testApp"
manifestPlaceholders = [
appAuthRedirectScheme: 'testSchema'
]
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testApp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:exported="true">
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<provider
android:name="com.vinzscam.reactnativefileviewer.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_viewer_provider_paths"
/>
</provider>
</application>
</manifest>
Fails on all 3 of these, but works fine on ‘Q’ or ‘Pie’ operating systems:

Environment
- Your Identity Provider: IdentityServer 4
- Platform that you’re experiencing the issue on: Android (specific to version ‘R’)
- Are you using Expo? No
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 9
- Comments: 61 (10 by maintainers)
It seems this ticket is diverging into different issues. The issue I’m referring to is the
Error: Data intent is nullerror.The problem I experienced was due to having deeplink integration already in place, using reactnavigation.
You won’t see this issue if you have not defined other intent-filters for the same auth scheme.
Based on the reactnavigation instructions, I have the following set in my
AndroidManifest.xml:And for
react-native-app-auth, I have set the following in mybuild.gradle:Note that adding the above effectively is the same as explicitly adding a new activity & intent filter like so:
So now we have two activities handling the same scheme.
The result of this is that after logging in, I’m presented with an “Open With” prompt that shows my app twice. I assume because there are now effectively two
intent-filter’s for the same scheme.If I select the app that’s handling the
.MainActivityactivity, I get theError: Data intent is nullerror. If I select the other app, the authentication works.To “fix” this, I followed @AlkanV’s advice and used a different scheme for the authentication redirect url, set in the build.gradle:
I then updated my redirect url to reflect the auth redirect scheme. After logging in, everything works. I don’t get the “open with” prompt and I don’t get the auth error. I don’t like that the app handles two different deeplinking schemes, but I’m not sure if this is a problem or not.
I will create a new ticket asking the library authors to update the example to include reactnavigation. Issue here: https://github.com/FormidableLabs/react-native-app-auth/issues/611
We have exactly the same issue in our project. @yberstad your reproduction steps are correct.
To trigger “Data intent is null” error, the user must:
To avoid the issue, the user, during step 4, must use Recent apps/Overview button/gesture to navigate back to the app.
For some reason, there is a difference in app-auth behavior depending on the user opening the app through the Home screen or Recent apps. One case always fails, the other succeeds.
We suspect it is due to onResume() method triggering finish() in AuthorizationManagementActivity.java of AppAuth-Android. https://github.com/openid/AppAuth-Android/blob/907ebbd890738e47c0c0c5d04fc6dfa6c449891b/library/java/net/openid/appauth/AuthorizationManagementActivity.java#L211
The issue is quite critical since in our case we need to use third-party banking apps to authenticate, so the users have to switch between apps. At the moment we have to manually instruct the users to use “Recent apps” instead of the home button, but that is not a good solution.
Same issue. Any updates?
Any update on this ? I am still facing same issue. I have applied all above changes but still facing same issue can some one help
1 change package name in redirectUrl com.YOUR_APP => com.YOUR_APP.auth
2 change the package name on the google website com.YOUR_APP => com.YOUR_APP.auth
3 in
build.gradle@anisimov74 i can’t share my manifest file as it contains a bunch of other activities and it will just confuse others. I can say that instead of using
appAuthRedirectSchemeI ended up explicitly adding theRedirectUriReceiverActivityactivity into my AndroidManifest.xml:I see you’ve tried the same, but your sheme looks wrong to me. Should
com.myappbecom.myapp.oauth?i resolved this by following steps:–
Add to application tag :
Remove from main activity:
I figured out the cause of the problem. There is a In Manifest.xml
android:taskAffinity="", which should prevent possible phishing via task hijacking. https://github.com/FormidableLabs/react-native-app-auth/issues/674@AlkanV thank you so much for your very quick response, much appreciated!
This is our current config:
/app/build.gradle:
And here is our current intent-filter’s in AndroidManifest.xml:
Should I change it to this?
Just a clarification, we are only getting “Data intent is null” for some our Android users. It is working for the majority of our users.
I resolved this by adding the link prefix into the build.gradle file
e.g. If the redirect URL is
ubdi://connect, then you need to haveubdilisted hereI tried all solutions but getting same issue “Data intent is null”. If anyone have more suggestion or solution then please describe ??
Incase you’re using firebase deep links or your deep link is more like
"https://www.blah.com/oauth"instead of the generic"com.blah.app", you can try thisNote: In the case of firebase, your
redirectUrlshould be"https://yourFirebaseUrl?link=theActualDeepLink(https://www.blah.com/oauth)&theRestOfTheUrl(&apn='blah'...etc)"You don’t need to specify
appAuthRedirectSchemein thebuild.gradleas it’ll resolve to having two activities.I no longer have the
Data intent is nullerror.However, I now have a
Response state param did not match request stateerror. I’m trying to authenticate with Spotify so It could be an unrelated issue.I’m out of ideas. IMO it would be useful if this repo has a reactnavigation example that people can refer to.
This is still issue for me and problem is that its only happending on some android devices!
@yberstad I’ve noticed some issues with this approach though: If the app is opened from Google play(install then open), then the first Bank login(where you have to navigate between apps) fails. Follow up logins are successful using the “home screen icon” method. (That’s the issue with android:launchMode ) The same scenario but using “recent apps” instead of “home screen icon” succeeds as before. If the app is opened for the first time from home screen, then everything works no matter what. If the app is opened from Google play, but the user logins with Email(no need for switching apps), then all works.
We also have a bank which prompts a user for extra input after the authentication. It is more unpredictable(probably due to an extra step). When user returns(with “home screen icon”) to the app it shows RN part instead of the webview. If the user clicks the Android back button, then the bowser is shown with extra final step of authentication. (That’s the issue with android:launchMode ) After clicking authenticate, the user is shown the RN part again, but login showed as failed. If the user closes the app and opens it again, they are authenticated and everything works.
So overall I think it’s a big win, since it doesn’t affect successful logins, but fixes previously unsuccessful login almost without issues.
@Aleksefo, thank you so much for your info, very helpful!
I was initially sceptic to change the android:launchMode, because I was not sure what implications it could have.
But after trying to grasp the concept, I cannot see that would have any implications to change it (especially since we only have one activity in our RN application).
I watched this series regarding the concept of lauchMode, https://www.youtube.com/watch?v=gRub-Pm_A0Q&t=36s, which was very helpful.
The fix seems to be to change android:launchMode to “singleTop” in AndroidManifest.xml @yberstad, @DanielSchwartz89 @netanelh
@netanelh sorry, did not see your post before now.
No, we have not figured this out yet. I have been able to reproduce the error (but not in a way I think the user does it):
I suspect that this is due to that we get a new instance of the app (using android:launchMode=“singleInstance”) and that the original intent is lost?
If i look in node_modules/react-native-app-auth/android/src/main/java/com/rnappauth/RNAppAuthModule.java I see this code:
@Override public void onNewIntent(Intent intent) { }The new intent is not “saved”, but I do not know if this has anything to do with? Again, I do not think this is what the users experiencing this error is actually doing.
If anyone have some new insights on this issue, it would be much appreciated!
Thank you for posting your solution @Shpadoinkle and @harunsmrkovic !
@KristineTrona Is this still an issue for you? I can’t reproduce this on my emulator. This is the Example app with the Identity Server 4 configuration running on Pixel 2 with API 30.