33import java .util .List ;
44import com .azure .identity .InteractiveBrowserCredential ;
55import com .azure .identity .InteractiveBrowserCredentialBuilder ;
6+ import com .google .gson .annotations .JsonAdapter ;
67import com .microsoft .graph .authentication .*;
78import okhttp3 .*;
89import com .microsoft .graph .httpcore .HttpClients ;
910import com .microsoft .graph .exceptions .*;
11+ import org .json .simple .JSONObject ;
12+ import org .json .simple .parser .JSONParser ;
13+ import org .json .simple .parser .ParseException ;
1014
1115public class interactiveBrowserSample {
1216
17+ //Replace CLIENT_ID with your own client id from an adequately configured app
18+ //for requirements visit:
19+ //https://github.com/Azure/azure-sdk-for-java/wiki/Set-up-Your-Environment-for-Authentication#enable-applications-for-interactive-browser-oauth-2-flow
1320 private final static String CLIENT_ID = "199e4de3-dd3b-4a51-b78a-86b801246e20" ;
21+
22+ //Set the scopes for your ms-graph request
1423 private final static List <String > SCOPES = Arrays .asList ("user.ReadBasic.All" );
1524
1625 public static void main (String args []) throws Exception {
@@ -32,8 +41,14 @@ private static void interactiveBrowser() throws AuthenticationException{
3241 httpClient .newCall (request ).enqueue (new Callback () {
3342 @ Override
3443 public void onResponse (Call call , Response response ) throws IOException {
35- String responseBody = response .body ().string ();
36- System .out .println (responseBody );
44+ JSONParser jsonParser = new JSONParser ();
45+ JSONObject responseJson = null ;
46+ try {
47+ responseJson = (JSONObject ) jsonParser .parse (response .body ().string ());
48+ } catch (ParseException e ) {
49+ e .printStackTrace ();
50+ }
51+ System .out .println (responseJson );
3752 }
3853
3954 @ Override
@@ -42,5 +57,4 @@ public void onFailure(Call call, IOException e) {
4257 }
4358 });
4459 }
45-
4660}
0 commit comments