66import java .util .Scanner ;
77
88import com .fasterxml .jackson .databind .ObjectMapper ;
9- import com .fasterxml . jackson . databind . type . TypeFactory ;
9+ import com .github . scribejava . apis . XeroApi20 ;
1010import com .github .scribejava .core .builder .ServiceBuilder ;
1111import com .github .scribejava .core .model .OAuth2AccessToken ;
1212import com .github .scribejava .core .model .OAuthRequest ;
@@ -31,13 +31,14 @@ public static void main(String... args) throws IOException, InterruptedException
3131 final String clientId = "your client id" ;
3232 final String clientSecret = "your client secret" ;
3333 final String callback = "your callback url" ;
34-
34+
3535 final String secretState = "secret" + new Random ().nextInt (999_999 );
3636 final OAuth20Service service = new ServiceBuilder (clientId )
3737 .apiSecret (clientSecret )
38- .defaultScope ("openid email profile offline_access accounting.settings accounting.transactions" ) // replace with desired scope
38+ // replace with desired scope
39+ .defaultScope ("openid email profile offline_access accounting.settings accounting.transactions" )
3940 .callback (callback )
40- .build (Xero20Api .instance ());
41+ .build (XeroApi20 .instance ());
4142 final Scanner in = new Scanner (System .in , "UTF-8" );
4243
4344 System .out .println ("=== " + NETWORK_NAME + "'s OAuth Workflow ===" );
@@ -71,33 +72,32 @@ public static void main(String... args) throws IOException, InterruptedException
7172 System .out .println ("Got the Access Token!" );
7273 System .out .println ("(The raw response looks like this: " + accessToken .getRawResponse () + "')" );
7374 System .out .println ();
74-
75+
7576 //First GET the Xero Tenant ID
7677 System .out .println ("Getting Xero tenant id..." );
7778 final OAuthRequest requestConn = new OAuthRequest (Verb .GET , PROTECTED_RESOURCE_URL );
7879 requestConn .addHeader ("Accept" , "application/json" );
7980 service .signRequest (accessToken .getAccessToken (), requestConn );
8081 final Response connResp = service .execute (requestConn );
81-
82- ObjectMapper objectMapper = new ObjectMapper ();
83- TypeFactory typeFactory = objectMapper .getTypeFactory ();
84- @ SuppressWarnings ("rawtypes" )
85- List <Map > tenantList = objectMapper .readValue (connResp .getBody (), typeFactory .constructCollectionType (List .class , Map .class ));
86-
82+
83+ final ObjectMapper objectMapper = new ObjectMapper ();
84+ final List <Map <String , String >> tenantList = objectMapper .readValue (connResp .getBody (),
85+ objectMapper .getTypeFactory ().constructCollectionType (List .class , Map .class ));
86+
8787 System .out .println ();
8888 System .out .println (connResp .getCode ());
8989 System .out .println (connResp .getBody ());
9090 System .out .println ();
9191 System .out .println ("Your Xero tenant id is ...." + tenantList .get (0 ).get ("tenantId" ));
9292 System .out .println ();
93-
93+
9494 // GET protected Resource
9595 System .out .println ("Now we're going to access a protected resource..." );
9696 final OAuthRequest request = new OAuthRequest (Verb .GET , PROTECTED_ORGANISATION_URL );
97- request .addHeader ("xero-tenant-id" ,tenantList .get (0 ).get ("tenantId" ). toString ( ));
97+ request .addHeader ("xero-tenant-id" , tenantList .get (0 ).get ("tenantId" ));
9898 service .signRequest (accessToken .getAccessToken (), request );
9999 final Response response = service .execute (request );
100-
100+
101101 // Now let's go and ask for a protected resource!
102102 System .out .println ("Got it! Lets see what we found..." );
103103 System .out .println ();
@@ -107,4 +107,4 @@ public static void main(String... args) throws IOException, InterruptedException
107107 System .out .println ();
108108 System .out .println ("Thats it man! Go and build something awesome with ScribeJava! :)" );
109109 }
110- }
110+ }
0 commit comments