Skip to content

Commit 177a977

Browse files
committed
1 parent ee703cb commit 177a977

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ScribeJava support out-of-box several HTTP clients:
5151
* [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java)
5252
* [RFC 5849](https://tools.ietf.org/html/rfc5849) The OAuth 1.0 Protocol, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java)
5353

54-
### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box
54+
### Supports all (50+) major 1.0a and 2.0 OAuth APIs out-of-the-box
5555

5656
* Asana (https://asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java)
5757
* Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java)
@@ -103,6 +103,7 @@ ScribeJava support out-of-box several HTTP clients:
103103
* Viadeo (http://viadeo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java)
104104
* VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java), [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java), [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java)
105105
* Wunderlist (https://www.wunderlist.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java)
106+
* Xero (https://www.xero.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java)
106107
* XING (https://www.xing.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java)
107108
* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java)
108109
* check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples)

changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[SNAPSHOT]
2+
* Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen)
3+
14
[6.8.1]
25
* make Response implements Closeable (thanks to https://github.com/omaric)
36
* fix Type resolution for builder pattern in ServiceBuilderOAuth10a (thanks to https://github.com/mgyucht)

scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.github.scribejava.apis;
22

33
import com.github.scribejava.core.builder.api.DefaultApi20;
4-
import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication;
5-
import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme;
64

75
/**
86
* Xero.com Api
@@ -13,6 +11,7 @@ protected XeroApi20() {
1311
}
1412

1513
private static class InstanceHolder {
14+
1615
private static final XeroApi20 INSTANCE = new XeroApi20();
1716
}
1817

@@ -29,9 +28,4 @@ public String getAccessTokenEndpoint() {
2928
protected String getAuthorizationBaseUrl() {
3029
return "https://login.xero.com/identity/connect/authorize";
3130
}
32-
33-
@Override
34-
public ClientAuthentication getClientAuthentication() {
35-
return RequestBodyAuthenticationScheme.instance();
36-
}
3731
}

scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Scanner;
77

88
import com.fasterxml.jackson.databind.ObjectMapper;
9-
import com.fasterxml.jackson.databind.type.TypeFactory;
9+
import com.github.scribejava.apis.XeroApi20;
1010
import com.github.scribejava.core.builder.ServiceBuilder;
1111
import com.github.scribejava.core.model.OAuth2AccessToken;
1212
import 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

Comments
 (0)