rmcfarlane82 / react-native-msal-plugin

React Native Plugin that wraps Microsoft MSAL library allowing you to authenticate with azure B2C
MIT License
15 stars 5 forks source link

React native image picker app crash on Android #19

Open phoenix377 opened 5 years ago

phoenix377 commented 5 years ago

Hello, we use this plugin and react-native-image-picker (https://github.com/react-native-community/react-native-image-picker).

But when we call ImagePicker.launchImageLibrary function of react-native-image-picker, app crashes and there is mention of RNMsalPlugin in the crash log:

    --------- beginning of crash
2019-03-11 16:00:14.182 24851-24851/com.springshot.SpringshotMobile E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.springshot.SpringshotMobile, PID: 24851
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=13002, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/156/ORIGINAL/NONE/159831847 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F156/ORIGINAL/NONE/159831847} }} to activity {com.springshot.SpringshotMobile/com.springshot.SpringshotMobile.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.microsoft.identity.client.PublicClientApplication.handleInteractiveRequestRedirect(int, int, android.content.Intent)' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
        at android.app.ActivityThread.-wrap19(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.microsoft.identity.client.PublicClientApplication.handleInteractiveRequestRedirect(int, int, android.content.Intent)' on a null object reference
        at com.reactlibrary.RNMsalPlugin.onActivityResult(RNMsalPlugin.java:43)
        at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:253)
        at com.facebook.react.ReactInstanceManager.onActivityResult(ReactInstanceManager.java:692)
        at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:129)
        at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:75)
        at android.app.Activity.dispatchActivityResult(Activity.java:7266)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312) 
        at android.app.ActivityThread.-wrap19(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
2019-03-11 16:00:14.185 24851-24851/com.springshot.SpringshotMobile E/com.marianhello.logging.UncaughtExceptionLogger: FATAL EXCEPTION: mainjava.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=13002, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/156/ORIGINAL/NONE/159831847 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F156/ORIGINAL/NONE/159831847} }} to activity {com.springshot.SpringshotMobile/com.springshot.SpringshotMobile.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.microsoft.identity.client.PublicClientApplication.handleInteractiveRequestRedirect(int, int, android.content.Intent)' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
        at android.app.ActivityThread.-wrap19(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.microsoft.identity.client.PublicClientApplication.handleInteractiveRequestRedirect(int, int, android.content.Intent)' on a null object reference
        at com.reactlibrary.RNMsalPlugin.onActivityResult(RNMsalPlugin.java:43)
        at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:253)
        at com.facebook.react.ReactInstanceManager.onActivityResult(ReactInstanceManager.java:692)
        at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:129)
        at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:75)
        at android.app.Activity.dispatchActivityResult(Activity.java:7266)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
        ... 9 common frames omitted

I also tried to use another image picker library, but still has similar crash report relating with react-native-msal library.

rmcfarlane82 commented 5 years ago

Hi, thanks for reporting the issue, were using react-native-image-crop-picker with no issues, could you perhaps create a basic app that reproduces the issue so that we can debug?

phoenix377 commented 5 years ago

Hi @rmcfarlane82 

I created demo app here - https://github.com/phoenix377/sample

And you can check how it is crashing through this video - https://www.dropbox.com/s/i22fzhmcoga258d/crash.mp4?dl=0

Please check it and let me know if it's enough for debug.

Thanks.

rmcfarlane82 commented 5 years ago

Brilliant We’ll have a look and see if we can solve the Issue issue-19-android-crash

phoenix377 commented 5 years ago

Hi @rmcfarlane82 , may I ask if there is update on this issue? Thanks.

rmcfarlane82 commented 5 years ago

@phoenix377, just trying to find some tome to fully test, should be looking at getting a beta release with the fix over the weekend.

rmcfarlane82 commented 5 years ago

@phoenix377 Hi Could you test this version on npm 3.0.1-beta.0

phoenix377 commented 5 years ago

@rmcfarlane82 Hi, the crash issue is fixed. Thanks.

But I've got another issue. I'm logging in with Azure AD B2C, and SCOPES is not defined in Azure dashboard. If I don't specify SCOPES, it causes error, so I set SCOPES as ["email"]. Login was working before with version 1.0.20, but now I've got following error.

Error: Error Domain=MSALErrorDomain Code=-42500 "(null)" UserInfo={MSALErrorDescriptionKey=Authentication response received without expected accessToken}

Could you please check it?

screenshot

rmcfarlane82 commented 5 years ago

Okay I'll see if i can help, what is the scope you are sending up in your request? in azure go to the application you've set up in b2c and if you have set up an App ID URI in the properties tab then you should have scopes available in the published scopes section

Capture

the scope you request has to have the full scope value, for example "https://reactnativemsalplugin.onmicrosoft.com/react-native/user_impersonation"

also just for security, i know its only your test b2c but i would blur stuff like client id in any images, just in-case.

phoenix377 commented 5 years ago

@rmcfarlane82 The Azure app is installed by our customer, and they don't need to setup App ID URI. So there is no scopes set. But authClient.aquireTokenB2CAsync cause error if I don't pass SCOPE parameter, so I pass scope as ["email"].

const AUTHORITY = "https://xxx.b2clogin.com/tfp/xxx.onmicrosoft.com";
const CLIENTID = "xxxx";
const SCOPES = ['email'];
const POLICIES = {
    signUpSignInPolicy: 'B2C_1_SignUp',
    passwordResetPolicy: 'B2C_1_edit_profile',
}

const authClient = new MsalPlugin(AUTHORITY, CLIENTID);
const result = await authClient.aquireTokenB2CAsync(SCOPES, POLICIES, { loginHint: email });

Btw, this code is working with version 1.0.2.

phoenix377 commented 5 years ago

@rmcfarlane82 , is there any news for the above issue?

rmcfarlane82 commented 5 years ago

Yes no joy yet, need to spend a bit more time on it, at the moment if you do not specify a valid scope that B2C knows about, you will not get an access token only an I’d token, so I’m changing it to allow only requesting an Id token if no valid scope is provided.

On 29 Apr 2019, at 17:44, phoenix377 notifications@github.com wrote:

@rmcfarlane82 , is there any news for the above issue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

cle5eland commented 5 years ago

@rmcfarlane82 is this fix (the app crashing fix) still in beta or is it part of the most recent release?

rmcfarlane82 commented 5 years ago

Still in beta, I’ll release it soon, I’ve not been able to work on the project for a couple of weeks, hopefully I’ll get back on react native asap.

On 14 May 2019, at 21:53, Cleveland Thompson notifications@github.com wrote:

@rmcfarlane82 is this fix (the app crashing fix) still in beta or is it part of the most recent release?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rishioid commented 5 years ago

I got the same issue, my app has google ans MS sign in, though signing in using google causes me this error. I believe some callback causing this.

09-18 11:24:43.061: E/AndroidRuntime(11211): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9001, result=0, data=Intent { (has extras) }} to activity {com.idealily/com.idealily.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.microsoft.identity.client.PublicClientApplication.handleInteractiveRequestRedirect(int, int, android.content.Intent)' on a null object reference 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.ActivityThread.deliverResults(ActivityThread.java:4360) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4402) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.os.Handler.dispatchMessage(Handler.java:106) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.os.Looper.loop(Looper.java:193) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.ActivityThread.main(ActivityThread.java:6669) 09-18 11:24:43.061: E/AndroidRuntime(11211): at java.lang.reflect.Method.invoke(Native Method) 09-18 11:24:43.061: E/AndroidRuntime(11211): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 09-18 11:24:43.061: E/AndroidRuntime(11211): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 09-18 11:24:43.061: E/AndroidRuntime(11211): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.microsoft.identity.client.PublicClientApplication.handleInteractiveRequestRedirect(int, int, android.content.Intent)' on a null object reference 09-18 11:24:43.061: E/AndroidRuntime(11211): at com.rmcfarlane.msalplugin.RNMsalPlugin.onActivityResult(RNMsalPlugin.java:46) 09-18 11:24:43.061: E/AndroidRuntime(11211): at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:262) 09-18 11:24:43.061: E/AndroidRuntime(11211): at com.facebook.react.ReactInstanceManager.onActivityResult(ReactInstanceManager.java:703) 09-18 11:24:43.061: E/AndroidRuntime(11211): at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:124) 09-18 11:24:43.061: E/AndroidRuntime(11211): at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:75) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.Activity.dispatchActivityResult(Activity.java:7454) 09-18 11:24:43.061: E/AndroidRuntime(11211): at android.app.ActivityThread.deliverResults(ActivityThread.java:4353) 09-18 11:24:43.061: E/AndroidRuntime(11211): ... 11 more