I'm writing a Java app that aquires a token via the provided MS utility lib called adal4j.
It provides finished methods, I just need to provide the username, password, authority and my clientid. The code looks like this and works perfectly:
public AuthenticationResult getAccessTokenFromUserCredentials() throws Exception {
AuthenticationContext context;
AuthenticationResult result;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(this.authority, false, service);
Future<AuthenticationResult> future = context.acquireToken(
"https://mysite.sharepoint.com", this.clientId, this.userName, password,
null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException(
"authentication result was null");
}
return result;
}
As I said, this works perfectly, but due to some proxy issues cannot be used where I need to use it.
My question is, can I get the accessToken via a simple HTTP request somehow? Like:
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("username", username);
conn.setRequestProperty("password", password);
Any tips for getting an access token from Java with a simple HTTP request would be greatly appreciated, thanks!