question

GroverSidhartha-3814 avatar image
0 Votes"
GroverSidhartha-3814 asked azure-cxp-api edited

MSALException java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference in android native app

I'm trying to use MSAL android library to implement Azure AD B2C authentication in our enterprise android native app. After generating the appropriate configuration and using it in the azure samples (Botth Java and Kotlin) I get the error

java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference

On checking the network logs it appears that the authentication response is missing the access_token. On searching the web I found this open issue on github that has a workaround/ instructions to get past this error but that didnt help.



I would really like to get this working.

azure-ad-b2cazure-ad-msal
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @GroverSidhartha-3814 , what documents/samples are you following? Can you please check that the scope of the token is correct?

Thank you,
James

0 Votes 0 ·

I've been working with the sample @ https://github.com/Azure-Samples/ms-identity-android-java.git

I used the configuration from my company's Azure portal and followed all directions given in the readme of the repo. I successfully get a login page with multiple auth providers, choose one and it seems to authenticate me but in returning from the auth page I get this exception.

Can you elaborate on what I need to check in the scope of the token? I was provided the scope by the identity and auth team in our company.

Thanks,
Sid

0 Votes 0 ·

1 Answer

JamesHamil-MSFT avatar image
0 Votes"
JamesHamil-MSFT answered GroverSidhartha-3814 commented

Hi @GroverSidhartha-3814 , I think the best bet is to open a support ticket so we can look at your code and environment. I can get you a free ticket if you email "azcommunity@microsoft.com" with subject "ATTN: James Hamil" and attach your subscription ID. Please let me know when you have done so.

Best,
James

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JamesHamil-MSFT thanks for the prompt reply. I have an update here. I finally got the authentication to work but not without quirks. We followed the directions in this github issue message and setup a new scope. That scope worked and got rid of the error for us. Now we can see the access token in the AuthenticationResult object but cannot see the id_token which we are interested in.

Additional info: From the MSAL-android-kotlin sample I figured that the id_token is accessible from authenticationResult.getAccount().claims["id_token"] but I am getting a null claims object.

I am still interested in pursuing this further for the id token, so please let me know if I should go ahead with sending an email to the azcommunity address with your attention.



0 Votes 0 ·

Hi @GroverSidhartha-3814 , thanks for the update! We've been looking into your issue and have a few documents which may help you in general. This is one Azure Sample, and this is another. For the null claims object issue, the feature might not be present in the Android version. However, this may work as a solution: https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/850#issuecomment-566821052

Please let me know if this helps!

Best,
James


0 Votes 0 ·

@JamesHamil-MSFT thanks a lot for that response. The github post you provided worked for us. In fact along with the id token we were able to get the claims as well with the same approach.

0 Votes 0 ·