As a part of API Test automation, we did created native client ID, assign the required resources to native client.
All you need adal4j-1.6.X.jar
public static AuthenticationResult getAuthToken(String username, String password,
String clientId, String authority, String tenant, String urii) throws Throwable {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
crypToUtil td= new crypToUtil();
crypToUtil cryptoUtil = new crypToUtil();
password = cryptoUtil.decrypt(password);
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(authority + tenant + "/", true,service);
Future<AuthenticationResult> future = context.acquireToken(urii, clientId, username, password,null);
result = future.get();
} catch (ExecutionException | MalformedURLException e) {
throw e.getCause();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException("authentication result was null, could be your input data were wrong ...");
}
return result;
}