ich einen msdynamics crm Trail Account haben, registrieren ich meine Crm in Azure Active Directory als Web app/api und URL als http://localhost und ich gab die Erlaubnis für Dynamics CRM Online als Delegierter Überprüfung Genehmigung.Frau Dynamik Web API 401 Unauthorized
Unten ist der Code, den ich die access_token
private static AuthenticationResult getAccessTokenFromUserCredentials() throws Exception {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY, false, service);
/*
* Replace {client_id} with ApplicationID and {password} with
* password that were used to create Service Principal above.
*/
ClientCredential credential = new ClientCredential(CLIENT_ID,CLIENT_SECRET);
Future<AuthenticationResult> future = context.acquireToken("https://XXXXXXXX.api.crm8.dynamics.com",
credential, null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException("authentication result was null");
}
return result;
}
Jetzt .. Ich erhalte
Ich bin mit dem access_token und den Code zu bekommen bin mit Leitungen ladenURL url = new URL(RESOURCE + "/api/data/v8.0/opportunities?$select=name,&$expand=parentcontactid($select=contactid,firstname,lastname,jobtitle,company,emailaddress1,telephone1,telephone2)&$filter=statecode%20eq%200");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setRequestProperty("OData-MaxVersion", "4.0");
connection.addRequestProperty("OData-Version", "4.0");
int responseCode = connection.getResponseCode();
System.out.println("res code : "+ responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
Aber ich bekomme Antwortcode 401 Nicht autorisierte. Kann mir bitte jemand helfen?
WebAPI gemeint ist wirklich von innen CRM verwendet werden. Von außen ist es besser, den Xrm.Tooling.Connector zu verwenden (ex-Xrm.Client) – Alex
Aber ich muss es über Rest API verbinden, ich soll nicht Soap-Endpunkt verwenden Ich löste diese Verwendung durch Zuweisen von Rollen und Hinzufügen Diese AAD-Client-ID für den Anwendungsbenutzer des CRM. Aber jetzt Aufgabe ist, ich sollte Azure ClientID und ClientSecret nicht verwenden, um CRM-Anmeldeinformationen (Benutzername/Passwort) zu verwenden, um eine Verbindung mit dem CRM herzustellen. Jede mögliche Hilfe würde geschätzt werden. – Jagan