Reputation: 1146
Hi i wrote a deamon app that uses Microsoft active directory, the app works fine in development environment but in production (AWS EC2 instance) i get this error :
java.lang.Exception: Server returned error in RSTR - ErrorCode: FailedAuthentication : FaultMessage: MSIS7068 : accès refusé.
at com.microsoft.aad.adal4j.WSTrustResponse.parse(WSTrustResponse.java:103) ~[adal4j-1.0.0.jar:1.0.0]
at com.microsoft.aad.adal4j.WSTrustRequest.execute(WSTrustRequest.java:69) ~[adal4j-1.0.0.jar:1.0.0]
at com.microsoft.aad.adal4j.AuthenticationContext.processPasswordGrant(AuthenticationContext.java:790) ~[adal4j-1.0.0.jar:1.0.0]
at com.microsoft.aad.adal4j.AuthenticationContext.access$000(AuthenticationContext.java:63) ~[adal4j-1.0.0.jar:1.0.0]
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:129) [adal4j-1.0.0.jar:1.0.0]
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:119) [adal4j-1.0.0.jar:1.0.0]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
2018-07-19 08:40:02.829 ERROR 5072 --- [nio-8083-exec-1] f.a.agent.reservation.utils.OAuth : java.util.concurrent.ExecutionException: java.lang.Exception: Server returned error in RSTR - ErrorCode: FailedAuthentication : FaultMessage: MSIS7068 : accès refusé.
I dont understand what's going on here because Dev and Prod envs are ISO.
This is the class that connects to active directory :
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import lombok.extern.java.Log;
@Log
public class OAuth {
private static String TOKEN = null;
private final static String AUTHORITY_URL = "https://login.microsoftonline.com/common/";
private final static String GRAPH_URL = "https://graph.microsoft.com";
private final static String CLIENT_ID = "*****";
private final static String USERNAME = "*****";
private final static String PASSWORD = "*****";
public static final String getToken() throws Exception {
if (null == TOKEN) {
AuthenticationContext context;
AuthenticationResult result = null;
ExecutorService service = null;
log.info("Auth with : " + USERNAME);
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY_URL, false, service);
Future<AuthenticationResult> future = context.acquireToken(GRAPH_URL, CLIENT_ID, USERNAME, PASSWORD, null);
result = future.get();
}catch (Exception e){
log.severe(e.toString());
} finally {
service.shutdown();
}
if (result == null) {
log.severe("AUTH FAILLURE");
} else {
TOKEN = result.getAccessToken();
}
}
return TOKEN;
}
}
Thank you.
Upvotes: 0
Views: 3177
Reputation: 1146
I just found the origin of this problem by trying to connect using a refresh token obtained from my company's network.
"error_description":"AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '00000003-0000-0000-c000-000000000000'.\r\nTrace ID: xxxxx\r\nCorrelation ID: xxxxxx b\r\nTimestamp: 2018-07-20 12:34:45Z","error":"interaction_required"
So i understand that two factor auth is not required from inside my company's network but it is required outside of it.
I will have to contact the administrator of office 365 in my company to have special account to authenticate without two factor authentication.
Upvotes: 1
Reputation: 30903
For the flow you are using (resource owner password credential
- by directly providing user credentials) you have to use the tenant specific endpoint. Which means, you have to change:
private final static String AUTHORITY_URL = "https://login.microsoftonline.com/common/";
to
private final static String AUTHORITY_URL = "https://login.microsoftonline.com/<tenant_id>/";
Where you can use your either tenant domain (i.e. yourdomain.onmicrosoft.com) or the tenant_id in <tenant_id>
.
Upvotes: 0