Reputation: 620
I am trying to connect Microsoft dynamics crm by web api in java
private final static String AUTHORITY = "XXXXXXXXXXXX";
private final static String CLIENT_ID = "XXXXXXXXXXXX";
private final static String RESOURCE = "XXXXXXXXXXXXXXXXXXX";
public static void main(String args[]) throws Exception {
try (BufferedReader br = new BufferedReader(new InputStreamReader(
System.in))) {
System.out.print("Enter username: ");
String username = br.readLine();
System.out.print("Enter password: ");
String password = br.readLine();
AuthenticationResult result = getAccessTokenFromUserCredentials(
username, password);
System.out.println("Access Token - " + result.getAccessToken());
System.out.println("Refresh Token - " + result.getRefreshToken());
System.out.println("ID Token - " + result.getIdToken());
}
}
private static AuthenticationResult getAccessTokenFromUserCredentials(
String username, String password) throws Exception {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY, false, service);
Future<AuthenticationResult> future = context.acquireToken(
RESOURCE, CLIENT_ID, username, password, null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException(
"authentication result was null");
}
return result;
}
}
I have a Ms dynamics account ,but I dont know how to get the AUTHORITY , CLIENT_ID and RESOURCE.
I tried by creating my app in https://portal.azure.com there I can see the application_id. is that the clientid I have to use.
Can anyone please tell me how can I get these Crendentials.
Thanks in Advance..
Upvotes: 2
Views: 965
Reputation: 2848
Client Id = Application Id
Resource = CRM Url
Authority = OAUTH 2.0 AUTHORIZATION ENDPOINT - found under Endpoints at the top of the App Registrations list
Upvotes: 3