0

I have cloned the partnerconsent project - https://github.com/Microsoft/Partner-Center-Java-Samples/tree/master/secure-app-model/keyvault from GIT to my local Eclipse.

I am getting an Execution exception on the line "future.get()" even though correct values are passed for authorization code, redirectUrl, clientId and clientSecret. Please advise how to resolve this/root cause.

  private AuthenticationResult getAccessToken(HttpServletRequest request, AuthorizationCode code)
    throws Throwable
{
    AuthenticationContext authContext; 
    AuthenticationResult authResult;
    ExecutorService service = null;
    Future<AuthenticationResult> future;

    try
    {
        service =  Executors.newFixedThreadPool(1);

        authContext = new AuthenticationContext(
            MessageFormat.format("{0}/common", authority), 
            true, 
            service);

        future = authContext.acquireTokenByAuthorizationCode(
            code.getValue(),
            new URI(redirectUrl),
            new ClientCredential(
                clientId,
                clientSecret), 
            null); 

        authResult = future.get();
    }
    catch(ExecutionException ex)
    {
        throw ex.getCause();
    }
    ...

    return authResult;
}

The method acquireTokenByAuthorizationCode is present in AuthenticationContext class of com.microsoft.aad.adal4j package which is a library used in the project.

public Future<AuthenticationResult> acquireTokenByAuthorizationCode(
        final String authorizationCode, final URI redirectUri,
        final ClientCredential credential,
        final AuthenticationCallback callback) {
    this.validateAuthCodeRequestInput(authorizationCode, redirectUri,
            credential, null);
    return this.acquireTokenByAuthorizationCode(authorizationCode,
            redirectUri, credential, null, callback);
}

Exception stack trace

java.lang.ClassCastException: class java.util.Collections$SingletonList cannot be cast to class java.lang.String (java.util.Collections$SingletonList and java.lang.String are in module java.base of loader 'bootstrap')
    at com.nimbusds.oauth2.sdk.util.URLUtils.serializeParameters(URLUtils.java:103)
    at com.microsoft.aad.adal4j.AdalTokenRequest.toOAuthRequest(AdalTokenRequest.java:160)
    at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:86)
    at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:930)
    at com.microsoft.aad.adal4j.AcquireTokenCallable.execute(AcquireTokenCallable.java:70)
    at com.microsoft.aad.adal4j.AcquireTokenCallable.execute(AcquireTokenCallable.java:38)
    at com.microsoft.aad.adal4j.AdalCallable.call(AdalCallable.java:47)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
ab.it.gcp
  • 151
  • 1
  • 14
  • The ExecutionException on the line "future.get()" can occur if there is an error in the execution of the acquireToken method – Suresh Chikkam Mar 10 '23 at 12:24
  • 1
    Unless the root cause is known, it won't help. I'm pretty sure that the credentials passed are correct. – ab.it.gcp Mar 10 '23 at 12:30

0 Answers0