authorize() returns error 'Data intent is null' on Android
See original GitHub issueIssue
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:50 (9 by maintainers)
Top Results From Across the Web
Intent data is null - java - Stack Overflow
try using this to get intent values getIntent().getStringExtra("photo") ;. or. Bundle b = new Bundle(); b = getIntent().
Read more >Intent - Android Developers
openInputStream() , allowing the user to pick one of them and then some data inside of it and returning the resulting URI to...
Read more >Stripe API reference – Errors – curl
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries....
Read more >Authenticate with Google on Android - Firebase
setGoogleIdTokenRequestOptions(GoogleIdTokenRequestOptions.builder() ... int resultCode, @Nullable Intent data) { ... if (idToken != null) {
Read more >AuthSession - Expo Documentation
Often times providers will fail to return the proper error message for a ... Parse a URL returned from the authorization server with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It seems this ticket is diverging into different issues. The issue I’m referring to is the
Error: Data intent is null
error.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
.MainActivity
activity, I get theError: Data intent is null
error. 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
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