in src/CsrValidation/java/lib/src/main/java/com/microsoft/intune/scepvalidation/IntuneClient.java [387:442]
private void RefreshServiceMap() throws ServiceUnavailableException, InterruptedException, ExecutionException, ClientProtocolException, IOException, AuthenticationException, IntuneClientException
{
String graphRequest = "";
String token = "";
boolean msalFailed = false;
Set<String> scopes = new HashSet<String>();
scopes.add(this.msGraphResourceUrl + ".default");
try
{
token = this.msalAuthClient.getAccessToken(scopes);
graphRequest = this.msGraphResourceUrl + "v" + this.msGraphVersion + "/servicePrincipals/appId="+ this.intuneAppId + "/endpoints";
}
catch(Exception e)
{
msalFailed = true;
}
if(msalFailed)
{
AuthenticationResult authResult = this.adalAuthClient.getAccessTokenFromCredential(this.aadGraphResourceUrl);
token = authResult.getAccessToken();
graphRequest = this.aadGraphResourceUrl + intuneTenant + "/servicePrincipalsByAppId/" + this.intuneAppId + "/serviceEndpoints?api-version=" + this.aadGraphVersion;
}
UUID activityId = UUID.randomUUID();
CloseableHttpClient httpclient = this.getCloseableHttpClient();
HttpGet httpGet = new HttpGet(graphRequest);
httpGet.addHeader("Authorization", "Bearer " + token);
httpGet.addHeader("client-request-id", activityId.toString());
CloseableHttpResponse graphResponse = null;
try
{
graphResponse = httpclient.execute(httpGet);
JSONObject jsonResult = ParseResponseToJSON(graphResponse, graphRequest, activityId);
for(Object obj:jsonResult.getJSONArray("value"))
{
JSONObject jObj = (JSONObject)obj;
String name = msalFailed ? jObj.getString("serviceName").toLowerCase() : jObj.getString("providerName").toLowerCase();
if(!serviceMap.containsKey(name))
{
serviceMap.put(name, jObj.getString("uri"));
}
}
}
finally
{
if(httpclient != null)
httpclient.close();
if(graphResponse != null)
graphResponse.close();
}
}