-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: App crashes if Intent data is null #52
Comments
I had the same issue when the intent URL was the same as the build.gradle:
Strings.xml:
(I added |
Thanks for the response, In android/app/build.gradle I made sure to set the following: This matches the file structure in android/app/...../java And in the strings.xml slightly different:
what am I doing wrong, im using the responseType: 'token', expecting the token to be returned in something like 'com.company.mobiletestapp://oauth#access_token=XXX' |
Also suffering with this one - trying to get it to work, and I can see the following in the phone log: 5 16:52:35.731 27554 27587 D GeckoViewNavigation[C]: loadURI: uri=xxx.yyyy.myapp://oauth#access_token=EwBwA8J%3d%3d&token_type=bearer&expires_in=3600&scope=https://graph.microsoft.com/.default%20https://graph.microsoft.com/Mail.Read%20https://graph.microsoft.com/User.Read&state=mfvymhWXGXLLgtdvZiQz where=1 flags=0x800000 tp=null So I can see that the phone is attempting to open a URI, and the handleOnActivityResult routine is being called in OAuth2ClientPlugin.java I put a logging line in there, and it logs that requestCode=2000, resultCode=0 and data=null. I tried various ways at getting the URI, but haven't succeeded yet - hopefully you might be able to give me some pointers. Interestingly, the next few capacitor log lines are:
04-15 16:52:35.910 26698 26698 V Capacitor/Plugin/App: Notifying listeners for event appUrlOpen |
I'm about to look into this as I'm currently working on the 2.0.0 release but I need your version information and config of the plugin.
Please create a new comment with your filled in data. |
A note at "Your Plugin Configuration": Plz mask your secret stuff and do not remove the parameter because I need to see which config parameters you're using. |
Michael,
Here is my config:
npx cap doctor
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 2.0.1
@capacitor/core: 2.0.1
@capacitor/android: 2.0.1
@capacitor/electron: 2.0.1
@capacitor/ios: 2.0.1
Installed Dependencies:
@capacitor/ios not installed
@capacitor/electron not installed
@capacitor/cli 2.0.1
@capacitor/core 2.0.1
@capacitor/android 2.0.1
Library version: "_id": "@byteowls/capacitor-oauth2@1.1.0",
OAuth provider: Azure App registration
Plugin config:
OAuth2AuthenticateOptions = {
appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
authorizationBaseUrl:
'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
accessTokenEndpoint: "https://graph.microsoft.com",
scope: "https://graph.microsoft.com/.default",
resourceUrl: "https://graph.microsoft.com/v1.0/me",
responseType: 'token',
web:{
// Maybe for device??
redirectUrl: 'com.xxxxxxx.xxxxxxxxxx://oauth',
// Works for web....??
//redirectUrl: 'http://localhost:8100',
windowOptions: 'width=500,height=600',
windowTarget: '_blank'
},
android: {
customScheme: "com.xxxxxxx.xxxxxxxxxx://oauth"
}
};
refreshOptions: OAuth2RefreshTokenOptions =
{
appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
accessTokenEndpoint:
'https://login.microsoftonline.com/common/oauth2/nativeclient',
refreshToken: ''
}
If you need anything else, then let know.
Steve
|
Tried something...added this to OAuth2ClientPlugin.java
04-15 21:16:43.899 19959 19959 E Capacitor/Plugin/OAuth2ClientPlugin: intent data: 2000 0 Note that the NewIntentHandler does fire when the app starts, but of course the scheme won't match unless the intent matches that from the OAuth2 redirect. |
Hi Steve, As your using Capacitor 2.x you will have to wait for 2.0.0 of this plugin because on iOS you will most probably run into a problem with XCode 11.4. See #74 for details. I'm working on better docs in a feature branch. Plz check if your Android configuration is valid. Regardless of that v1.1.0 is not intended to work with Capactior 2.x only v2.0.0 will. BR, Michael |
@steve-allam Thx for the |
@steve-allam Could you describe the steps on your phone until the error occurs. eg.
Which Android versions and devices do you test on? I can only think of a situation when the Android system or the user closes the Capacitor App after Chrome is launched. I also look into According to the Capacitor Docs the way I handle the result of a activity should be fine. Android itself proposes the use of new AndroidX features to handle the result but that's not supported by Capacitor right now. (Plugin, Bridge) I'll try changing the plugin's request code to sth more unique. Maybe another plugin uses the same but that should not be a problem because both plugins would get the intent. |
Michael,
Steps are:
1. Launch app
2. Click login button
3. First (Chrome) screen appears, asking for username
4. MS redirect to live.com, and ask if I am trying to authenticate with
my (named) app with the credentials I just gave them
(This screen appears I assume as I already have an authenticated
session from when I succeeded with the ionic web app
5. I click "continue", which indicates that I am trying to do so.
6. Chrome closes
7. App crashes.
a - or...in my modified version, the handleOnNewIntent is called, as
well as the handleOnActivityResult
- handleOnNewIntent shows me the full URI for the redirect URL,
including authentication token
- handleOnActivityResult catches the null (my change) and
returns a fail
- So my changes haven't fixed anything, just shown that the
OnActivityResult passes a null intent (I also put logging in the Bridge
routine, it is null there), but the handleOnNewIntent is definitely
called for the redirect URI.
You say that OnNewIntent is only called on load - if that is the case,
then the problem might well be because the app stops - would you like my
full log?
Having looked closer, the sequence appears to be:
04-15 23:06:08.264 24671 24820 D Capacitor: Starting activity for result
04-15 23:06:08.302 2711 2892 I ActivityManager: START u0 {act=null
typ=null flg=0x0
cmp=ComponentInfo{com.domain.myapp/net.openid.appauth.AuthorizationManagementActivity}}
from uid 10345 on display 0
- Activity manager is tasked with starting a new activity (for which you
await the result).
This activity generally happens....then it kinda looks like the system
is trying to reactivate the activity:
04-15 23:06:09.455 2711 7683 V WindowManager: Relayout
Window{4c7424ad0 u0
com.domain.myapp/net.openid.appauth.AuthorizationManagementActivity}:
viewVisibility=8 req=720x1280 WM.LayoutParams{(0,0)(fillxfill) sim=#120
ty=1 fl=#1810100 pfl=0x20000 fmt=-2 wanim=0x1030000 vsysui=0x400
needsMenuKey=2 naviIconColor=0}
Then...well, I don't know what it is doing...
04-15 23:06:09.568 2711 7683 I WindowManager_SurfaceController:
Destroying surface
Surface(name=com.domain.myapp/net.openid.appauth.AuthorizationManagementActivity)
called by com.android.server.wm.WindowStateAnimator.destroySurface:3040
com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:1148
com.android.server.wm.WindowState.destroyOrSaveSurface:2759
com.android.server.wm.WindowManagerService.tryStartExitingAnimation:3672
com.android.server.wm.WindowManagerService.relayoutWindow:3481
com.android.server.wm.Session.relayout:240
android.view.IWindowSession$Stub.onTransact:288
com.android.server.wm.Session.onTransact:161
...destroying the window? But after that, the capacitor app does
stop...
04-15 23:06:09.622 24671 24671 D Capacitor: Saving instance state!
04-15 23:06:09.624 24671 24671 D Capacitor/Plugin/App: Firing change:
false
04-15 23:06:09.624 24671 24671 V Capacitor/Plugin/App: Notifying
listeners for event appStateChange
04-15 23:06:09.624 2711 2787 I ActivityManager: Displayed
org.mozilla.firefox/org.mozilla.gecko.customtabs.CustomTabsActivity:
+1s27ms (total +1s272ms)
04-15 23:06:09.624 24671 24671 D Capacitor/Plugin/App: No listeners
found for event appStateChange
04-15 23:06:09.627 2711 7690 I ActivityManager: DSS on for
com.enhance.gameservice and scale is 1.0
04-15 23:06:09.643 24671 24671 D Capacitor: App stopped
04-15 23:06:09.652 2711 3349 V WindowManager: Relayout
Window{a7ac76cd0 u0 com.domain.myapp/com.domain.myapp.MainActivity
EXITING}: viewVisibility=8 req=720x1280 WM.LayoutParams{(0,0)(fillxfill)
sim=#20 ty=1 fl=#81810100 pfl=0x20000 wanim=0x1030465 vsysui=0x600
needsMenuKey=2 naviIconColor=0}
Then, the next capacitor line is (my log line from OnNewIntent):
04-15 23:06:28.274 24671 24671 E Capacitor/Plugin/OAuth2ClientPlugin:
intent data:
com.domain.myapp://oauth#access_token=<token>%2bSCAg%3d%3d&token_type=bearer&expires_in=3600&scope=https://graph.microsoft.com/.default%20https://graph.microsoft.com/Mail.Read%20https://graph.microsoft.com/User.Read&state=rAX5KD3ue4Q2NPPNit4F
So it does appear that the app stopped, and the newIntent restarted it?
If you would like full logs, then please let me know and I'll email them
direct.
Steve
|
Hey Steve, thx for the detailed response. I will most likely support both cases and introduce a Android option to switch it on/off. The default settings will depend on the outcome of my tests. If the BR, Michael |
I tested with API Level 29, 28, 27 in Simulator and 26 on a real device and The app will not crash any more and I introduced a new Android config parameter |
OAuth2ClientPlugin.java line 222 < response = AuthorizationResponse.fromIntent(data);>
Will crash the application when data is null.
When chrome custom tabs(used by AppAuth) redirect back to the application using the uri scheme, the data provided to handleOnActivityResult can be null.
Passing this to the AuthorizationReponse.fromIntent causes the application to crash.
Edit:
The same sort of issue can be found here
The text was updated successfully, but these errors were encountered: