简体   繁体   中英

trying to connect Microsoft dynamics crm by web api in java

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..

Client Id = Application Id

Resource = CRM Url

Authority = OAUTH 2.0 AUTHORIZATION ENDPOINT - found under Endpoints at the top of the App Registrations list

An elaborate tutorial on connecting from Java to MS Dynamics, with OAuth2 authentication from Java via ADFS (Microsoft), is available here . The Java library OLingo is used to read objects (EntitySets) via the OData-interface from 'Dynamics' into Java classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM