"Failed to authorize: Null intent received" when using deeplink to bring app in front under android
Hello everyone, Hello MaikuB,
I have a multi-step authentication process in the course of which the user does something in another app. To do this, I first call authoriseAndExchangeCode. During the authentication process, another app is called from the custom Android tab or the ASAuthenticationSession. To bring the custom app back into the foreground after the activities in the other app, I have defined another Android app link/deeplink/intent filter in the main activity. This deeplink is then called from the other app. After the return, the Android custom tab or the ASAuthentificationSession should still be visible. The problem is that under android the authentication is cancelled after the return and authorizeAndExchangeCode throws a PlatformException(null_intent, Failed to authorize: Null intent received, null, null). However, this flow works on iOS.
The following is an excerpt from the AndroidManifest.xml
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleInstance"
android:showWhenLocked="false"
android:theme="@style/LaunchTheme"
android:turnScreenOn="true"
android:windowSoftInputMode="adjustResize">
...
<!-- This activity is used for jump back-->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:host="my-host.tld"/>
<data android:path="/launch-my-app"/>
</intent-filter>
</activity>
<!-- This activity is later used for auth with AppAuth-->
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
android:exported="true"
tools:node="replace">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:host="my-other-host.tld"/>
<data android:path="/auth"/>
</intent-filter>
</activity>
The error seems to be due to the fact that onActivityResult(int requestCode, int resultCode, Intent intent) is called although the authentication has not yet been completed.
Does anyone have an idea what I can do or how I can fix this?
i got same issue. I set on file build.gradle and AndroidManifest.xml.
this solved my issue https://github.com/MaikuB/flutter_appauth/issues/503#issuecomment-2165906205
this solved my issued #503 (comment)
My AndroidManifest.xml unfortunately doesn't have a android:taskAffinity="" Attribute.
I am having the same issue
I have no experience in native Android development so I don't know exactly how this works but I added an intent-filter inside my main activity :
<intent-filter android:autoVerify="true">
<action android:name="HANDLE_AUTHORIZATION_RESPONSE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Can't find the source but it fixed the error for me.
I have no experience in native Android development so I don't know exactly how this works but I added an intent-filter inside my main activity :
<intent-filter android:autoVerify="true"> <action android:name="HANDLE_AUTHORIZATION_RESPONSE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>Can't find the source but it fixed the error for me
Thanks for the tip, I'll give it a try. How did you come up with this? What does your Android manifest look like overall? Did you add this in addition to the activity for the app link to return or the AppAuth activity or instead of one of the two?
I have no experience in native Android development so I don't know exactly how this works but I added an intent-filter inside my main activity :
<intent-filter android:autoVerify="true"> <action android:name="HANDLE_AUTHORIZATION_RESPONSE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>Can't find the source but it fixed the error for me.
This one worked for me I added this other intent and that did the job.
If you're encountering the error "Failed to authorize: Null intent received", it might be due to a missing or improperly configured AppAuth Redirect Activity in your AndroidManifest.xml.
Steps to Fix
Ensure the tools namespace is included in your manifest tag:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
Add a separate activity for handling authentication redirects below your main activity, update the values of your_scheme and your_host match your authentication provider’s redirect URI:
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
android:theme="@style/Theme.AppCompat.Translucent.NoTitleBar"
android:exported="true"
tools:node="replace">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="your_scheme" android:host="your_host"/>
</intent-filter>
</activity>
This should help resolve the issue 🚀
Description:
I encountered an issue when trying to authenticate using flutter_appauth and keycloak_wrapper. The following error messages were thrown:
E/OpenGLRenderer( 5083): Unable to match the desired swap behavior.
I/flutter ( 5083): errors occurred || Failed to login. || PlatformException(null_intent, Failed to authorize: Null intent received, , null) || #0 MethodChannelFlutterAppAuth.invokeMethod (package:flutter_appauth_platform_interface/src/method_channel_flutter_appauth.dart:120:9)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): #1 MethodChannelFlutterAppAuth.authorizeAndExchangeCode (package:flutter_appauth_platform_interface/src/method_channel_flutter_appauth.dart:38:42)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): #2 KeycloakWrapper.login (package:keycloak_wrapper/src/wrapper.dart:100:23)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): #3 LoginScreen.login (package:exp_emo/main.dart:122:24)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): isLoggedIn || false
Steps to Reproduce:
- Use the
flutter_appauthpackage for authentication. - Integrate it with
keycloak_wrapperfor Keycloak authentication. - Attempt to log in and encounter the issue.
Expected Behavior:
Successful login and authorization process using flutter_appauth and keycloak_wrapper.
Actual Behavior:
The application fails to log in, throwing a PlatformException with a Null intent received message.
FYI I am using the same code provided in the sample
Log Output:
E/OpenGLRenderer( 5083): Unable to match the desired swap behavior.
I/flutter ( 5083): errors occurred || Failed to login. || PlatformException(null_intent, Failed to authorize: Null intent received, , null) || #0 MethodChannelFlutterAppAuth.invokeMethod (package:flutter_appauth_platform_interface/src/method_channel_flutter_appauth.dart:120:9)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): #1 MethodChannelFlutterAppAuth.authorizeAndExchangeCode (package:flutter_appauth_platform_interface/src/method_channel_flutter_appauth.dart:38:42)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): #2 KeycloakWrapper.login (package:keycloak_wrapper/src/wrapper.dart:100:23)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): #3 LoginScreen.login (package:exp_emo/main.dart:122:24)
I/flutter ( 5083): <asynchronous suspension>
I/flutter ( 5083): isLoggedIn || false