AzureAD / microsoft-authentication-library-for-java

Microsoft Authentication Library (MSAL) for Java http://aka.ms/aadv2
MIT License
285 stars 141 forks source link

extraQueryParameters does not work when using msal4j-brokers #677

Closed flowchart87 closed 10 months ago

flowchart87 commented 1 year ago

Hi all!

extraQueryParameter does not work when using msal4j-brokers 1.0.2-beta and previous.

This instructions:

InteractiveRequestParameters parameters = InteractiveRequestParameters
    .builder(new URI("http://URI"))
    .scopes(scope)
    .windowHandle(1)
    .domainHint(domainHint)
    .loginHint(loginHint)
    .prompt(Prompt.LOGIN)
    .extraQueryParameters(MapOf("hsu","1))
    .build() 

generate following exception:


Exception in thread "main" java.lang.NullPointerException: String initializer must be non-null
    at com.sun.jna.WString.<init>(WString.java:33)
    at com.microsoft.azure.javamsalruntime.AuthParameters$AuthParametersBuilder.additionalParameters(AuthParameters.java:104)

Function in which exception occours:

 public AuthParametersBuilder additionalParameters(Map<String, String> parameters) {
            if (parameters != null) {
                for (Map.Entry<String, String> param : parameters.entrySet()) {
                    MsalRuntimeInterop.ERROR_HELPER.checkMsalRuntimeError(
                            MsalRuntimeInterop.MSALRUNTIME_LIBRARY.MSALRUNTIME_SetAdditionalParameter(
                                    handle.value(), new WString(param.getKey()),
                                    new WString(parameters.get(param.getValue()))));
                }
            }
            return this;
        }

error does not occur using only MSAL4j

Avery-Dunn commented 1 year ago

Hello @flowchart87 : Thanks for bringing this to our attention, it looks like the bug is from a mistake during some refactoring.

In that additionalParameters() method the line new WString(parameters.get(param.getValue())) is incorrectly trying to get a value from the original parameters map, and instead it should simply be new WString(param.getValue())

This will be fixed in the next beta release, and I'll update this thread once it's available.

Avery-Dunn commented 10 months ago

Sorry for the lack of update on this, however this issue was fixed in an internal-focused beta release, and has just been officially released as part of version 1.14.0 of msal4j and 1.0.0 of msal4j-brokers.