Android Dynamics CRM adal4j Login Issue

I use Microsoft aad: adal4j to handle the dynamic crm login from Mobile. After implementation, I get the following exception.

What am I doing wrong?

Mistake

java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar) java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar) at java.util.concurrent.FutureTask.report(FutureTask.java:94) at java.util.concurrent.FutureTask.get(FutureTask.java:164) at com.sampleadal.MainActivity.onCreate(MainActivity.java:33) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar) at com.microsoft.aad.adal4j.AuthenticationContext.computeSha256Hash(AuthenticationContext.java:798) at com.microsoft.aad.adal4j.AuthenticationContext.logResult(AuthenticationContext.java:775) at com.microsoft.aad.adal4j.AuthenticationContext.access$200(AuthenticationContext.java:61) at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:130) at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:117) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) 

the code

 AuthenticationResult result = (AuthenticationResult) new AuthenticationContext(Constants.AUTHORITY_URL, false, Executors.newFixedThreadPool(1)).acquireToken(Constants.SERVICE_URL, Constants.CLIENT_ID, "my_login_id", "my_password", null).get(); Log.d("TAG", "Access Token - " + result.getAccessToken() + " \n Refresh Token - " + result.getRefreshToken() + " \n ID Token - " + result.getAccessToken() + " \n User ID - " + result.getUserInfo().getUniqueId() + " \n Displayable ID - " + result.getUserInfo().getDispayableId()); 

Gradle file

 compile 'com.microsoft.aad:adal4j:0.0.2' 

And also tried this:

The code:

 AuthenticationResult result = (AuthenticationResult) new AuthenticationContext(Constants.AUTHORITY_URL, false, Executors.newFixedThreadPool(1)).acquireToken(Constants.SERVICE_URL, new ClientCredential("my_login_id", "my_password"), null).get(); 

Exit

  { "error": "unauthorized_client", "error_description": "AADSTS70001: Application with identifier 'prasanth' was not found in the directory windows.net\r\nTrace ID: 8c5ccd53-af99-4ff0-8556-501a53080d2f\r\nCorrelation ID: 8651e7f1-a7db-4673-aafb-52fef0d48d2d\r\nTimestamp: 2016-09-26 06:10:41Z" } 
+7
java android dynamics-crm adal4j
source share
2 answers

com.microsoft.aad / adal is the Azure Active Directory library for Android applications, and com.microsoft.azure/adal4j is the Azure Active Directory library for Java web applications.

http://mvnrepository.com/artifact/com.microsoft.aad/adal/1.0.0 http://mvnrepository.com/artifact/com.microsoft.azure/adal4j

+2
source share

@abhishesh already pointed out the right solution. The adald4j library for java was not developed for android and uses a different version of the apache commons library, as android does internally. I ran into the same problem using the figo connect API (www.figo.io).

What you need to do:

  • Download the adald4j library https://github.com/AzureAD/azure-activedirectory-library-for-java and add it to your project locally.

  • Download the apache commons library and rename all its package names (for example, "org.apache.commons.codec.android"). For example, use search and replace in multiple files in sublime text. Add the local apache library locally.

  • Rename all versions of the apache packages common in your loaded adald4j library to your new specified name. This ensures that the library uses your version of apache commons and not the internal version of Android.

+1
source share

All Articles