Flutter app crashes with "Invalid, null, or malformed redirect_uri supplied" error when using MSAL in release mode

Muhammad Zohaib Tariq 1 Reputation point
2022-12-20T12:03:22.99+00:00

I am using MSAL (Microsoft Authentication Library) in a Flutter app and when I try to run the app in release mode, it crashes with the following error:

Fatal Exception: java.lang.IllegalArgumentException: Invalid, null, or malformed redirect_uri supplied
at com.microsoft.identity.client.PublicClientApplicationConfiguration.validateRedirectUri(:45)
at com.microsoft.identity.client.PublicClientApplicationConfiguration.validateConfiguration(:2)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.initializeConfigurationInternal(:14)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.initializeConfiguration(:9)
at com.microsoft.identity.client.PublicClientApplication$7.run(:4)
at java.lang.Thread.run(Thread.java:764)
I am using native code in my Flutter app and I have properly configured the redirect URI for my app, but I am still seeing this error.

I am creating a JSON file in native android and passing

client_id, resource_id, redirect_ui, tenant_id
From flutter to native android because we have different users with different credentials like client_id, redirect_ui etc. And that JSON file we're using native android.

PublicClientApplication.createSingleAccountPublicClientApplication(context,   File("/data/data/" + context.getPackageName().toString() + "/" +"config.json"),  
                object : ISingleAccountApplicationCreatedListener {  
                    override fun onCreated(application: ISingleAccountPublicClientApplication) {  
  
                        mSingleAccountApp = application  
                        callBack(LoginModel(error = false,message = "initialized data",token = null))  
                        loadAccount()  
                    }  
  
                    override fun onError(exception: MsalException) {  
                        callBack(LoginModel(error = true,message = exception.message,token = null))  
                          
                    }  
                })  

The is the method for initializing object of ISingleAccountPublicClientApplication and it was working fine in debug mode.

I have tried double-checking the redirect URI configuration, checking for typos or other mistakes in the URI, and checking for issues with the authorization request, but I am still having trouble resolving this issue.

Any help or suggestions on how to troubleshoot this error would be greatly appreciated.

Microsoft Security Microsoft Entra Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2022-12-21T07:19:47.197+00:00

    Hi @Muhammad Zohaib Tariq ,

    Thanks for reaching out.

    I understand you are trying to authenticate from flutter application using android and getting error.

    This could be due to while registering the application there might be issue with Signature Hash. To create the hash on the command line, make sure to use the password for your android keystore (default is 'android') rather than default password.

    Similar issue in stackoverflow : https://stackoverflow.com/questions/58757706/unable-to-create-singleaccountpublicclientapplication-for-azure-ad-on-android

    Hope this will help.

    Thanks,
    Shweta

    ----------------------------

    Please remember to "Accept Answer" if answer helped you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.