Skip to content

Commit f7aaa7c

Browse files
committed
fixes after switching to jackson
1 parent 7d2ce91 commit f7aaa7c

47 files changed

Lines changed: 199 additions & 167 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,34 @@ public class FacebookAccessTokenErrorResponse extends OAuthException {
1919
private static final long serialVersionUID = -1277129766099856895L;
2020

2121
private final String type;
22-
private final String code;
22+
private final int codeInt;
2323
private final String fbtraceId;
2424
private final String rawResponse;
2525

26+
/**
27+
* @param message message
28+
* @param type type
29+
* @param code code
30+
* @param fbtraceId fbtraceId
31+
* @param rawResponse rawResponse
32+
* @deprecated use {@link #FacebookAccessTokenErrorResponse(java.lang.String, java.lang.String, int,
33+
* java.lang.String, java.lang.String)}
34+
*/
35+
@Deprecated
2636
public FacebookAccessTokenErrorResponse(String message, String type, String code, String fbtraceId,
2737
String rawResponse) {
2838
super(message);
2939
this.type = type;
30-
this.code = code;
40+
this.codeInt = Integer.parseInt(code);
41+
this.fbtraceId = fbtraceId;
42+
this.rawResponse = rawResponse;
43+
}
44+
45+
public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId,
46+
String rawResponse) {
47+
super(message);
48+
this.type = type;
49+
this.codeInt = code;
3150
this.fbtraceId = fbtraceId;
3251
this.rawResponse = rawResponse;
3352
}
@@ -36,8 +55,17 @@ public String getType() {
3655
return type;
3756
}
3857

58+
/**
59+
* @return code
60+
* @deprecated use {@link #getCodeInt() }
61+
*/
62+
@Deprecated
3963
public String getCode() {
40-
return code;
64+
return Integer.toString(codeInt);
65+
}
66+
67+
public int getCodeInt() {
68+
return codeInt;
4169
}
4270

4371
public String getFbtraceId() {
@@ -54,7 +82,7 @@ public int hashCode() {
5482
hash = 83 * hash + Objects.hashCode(rawResponse);
5583
hash = 83 * hash + Objects.hashCode(getMessage());
5684
hash = 83 * hash + Objects.hashCode(type);
57-
hash = 83 * hash + Objects.hashCode(code);
85+
hash = 83 * hash + Objects.hashCode(codeInt);
5886
hash = 83 * hash + Objects.hashCode(fbtraceId);
5987
return hash;
6088
}
@@ -80,15 +108,15 @@ public boolean equals(Object obj) {
80108
if (!Objects.equals(type, other.getType())) {
81109
return false;
82110
}
83-
if (!Objects.equals(code, other.getCode())) {
111+
if (codeInt != other.getCodeInt()) {
84112
return false;
85113
}
86114
return Objects.equals(fbtraceId, other.getFbtraceId());
87115
}
88116

89117
@Override
90118
public String toString() {
91-
return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'code'='" + code
119+
return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'codeInt'='" + codeInt
92120
+ "', 'fbtraceId'='" + fbtraceId + "', 'rawResponse'='" + rawResponse
93121
+ "', 'message'='" + getMessage() + "'}";
94122
}

‎scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java‎

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

3+
import com.fasterxml.jackson.databind.JsonNode;
34
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
45
import java.io.IOException;
5-
import java.util.Map;
66

77
/**
88
* non standard Facebook Extractor
@@ -32,12 +32,10 @@ public static FacebookAccessTokenJsonExtractor instance() {
3232
*/
3333
@Override
3434
public void generateError(String rawResponse) throws IOException {
35-
@SuppressWarnings("unchecked")
36-
final Map<String, String> response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER
37-
.readValue(rawResponse, Map.class);
35+
final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse).get("error");
3836

39-
throw new FacebookAccessTokenErrorResponse(response.get("message"), response.get("type"), response.get("code"),
40-
response.get("fbtrace_id"), rawResponse);
37+
throw new FacebookAccessTokenErrorResponse(errorNode.get("message").asText(), errorNode.get("type").asText(),
38+
errorNode.get("code").asInt(), errorNode.get("fbtrace_id").asText(), rawResponse);
4139
}
4240

4341
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.github.scribejava.apis.fitbit;
22

3+
import com.fasterxml.jackson.databind.JsonNode;
34
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
45
import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse;
56
import com.github.scribejava.core.oauth2.OAuth2Error;
67
import java.io.IOException;
7-
import java.util.List;
8-
import java.util.Map;
98

109
public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor {
1110

@@ -23,29 +22,27 @@ public static FitBitJsonTokenExtractor instance() {
2322

2423
@Override
2524
protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn,
26-
String refreshToken, String scope, Map<String, String> response, String rawResponse) {
25+
String refreshToken, String scope, JsonNode response, String rawResponse) {
2726
return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
28-
response.get("user_id"), rawResponse);
27+
response.get("user_id").asText(), rawResponse);
2928
}
3029

3130
/**
3231
* Related documentation: https://dev.fitbit.com/build/reference/web-api/oauth2/
3332
*/
3433
@Override
3534
public void generateError(String rawResponse) throws IOException {
36-
@SuppressWarnings("unchecked")
37-
final Map<String, List<Map<String, String>>> response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER
38-
.readValue(rawResponse, Map.class);
35+
final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse)
36+
.get("errors").get(0);
3937

40-
final Map<String, String> errorResponse = response.get("errors").get(0);
4138
OAuth2Error errorCode;
4239
try {
43-
errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorResponse, "errorType", rawResponse));
40+
errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorNode, "errorType", rawResponse).asText());
4441
} catch (IllegalArgumentException iaE) {
4542
//non oauth standard error code
4643
errorCode = null;
4744
}
4845

49-
throw new OAuth2AccessTokenErrorResponse(errorCode, errorResponse.get("message"), null, rawResponse);
46+
throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, rawResponse);
5047
}
5148
}

‎scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java‎

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

3+
import com.fasterxml.jackson.databind.JsonNode;
34
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
4-
import java.util.Map;
55

66
/**
77
* additionally parses OpenID id_token
@@ -22,8 +22,8 @@ public static OpenIdJsonTokenExtractor instance() {
2222

2323
@Override
2424
protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn,
25-
String refreshToken, String scope, Map<String, String> response, String rawResponse) {
25+
String refreshToken, String scope, JsonNode response, String rawResponse) {
2626
return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
27-
response.get("id_token"), rawResponse);
27+
response.get("id_token").asText(), rawResponse);
2828
}
2929
}

‎scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java‎

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

3+
import com.fasterxml.jackson.databind.JsonNode;
34
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
4-
import java.util.Map;
55

66
/**
77
* This extractor parses in addition to the standard Extractor the instance_url
@@ -23,8 +23,8 @@ public static SalesforceJsonTokenExtractor instance() {
2323

2424
@Override
2525
protected SalesforceToken createToken(String accessToken, String tokenType, Integer expiresIn,
26-
String refreshToken, String scope, Map<String, String> response, String rawResponse) {
26+
String refreshToken, String scope, JsonNode response, String rawResponse) {
2727
return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope,
28-
extractRequiredParameter(response, "instance_url", rawResponse), rawResponse);
28+
extractRequiredParameter(response, "instance_url", rawResponse).asText(), rawResponse);
2929
}
3030
}

‎scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.scribejava.apis.vk;
22

3+
import com.fasterxml.jackson.databind.JsonNode;
34
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
4-
import java.util.Map;
55

66
/**
77
* additionally parses email
@@ -22,8 +22,9 @@ public static VKJsonTokenExtractor instance() {
2222

2323
@Override
2424
protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn,
25-
String refreshToken, String scope, Map<String, String> response, String rawResponse) {
26-
return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response.get("email"),
27-
rawResponse);
25+
String refreshToken, String scope, JsonNode response, String rawResponse) {
26+
final JsonNode email = response.get("email");
27+
return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
28+
email == null ? null : email.asText(), rawResponse);
2829
}
2930
}

‎scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException
4242
final String code = in.nextLine();
4343
System.out.println();
4444

45-
// Trade the Request Token and Verfier for the Access Token
46-
System.out.println("Trading the Request Token for an Access Token...");
45+
System.out.println("Trading the Authorization Code for an Access Token...");
4746
OAuth2AccessToken accessToken = service.getAccessToken(code);
4847
System.out.println("Got the Access Token!");
4948
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");

‎scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException
4242
//pass access_type=offline to get refresh token
4343
final Map<String, String> additionalParams = new HashMap<>();
4444
additionalParams.put("access_type", "offline");
45-
//force to reget refresh token (if usera are asked not the first time)
45+
//force to reget refresh token (if user are asked not the first time)
4646
additionalParams.put("prompt", "consent");
4747
final String authorizationUrl = service.createAuthorizationUrlBuilder()
4848
.state(secretState)
@@ -68,8 +68,7 @@ public static void main(String... args) throws IOException, InterruptedException
6868
System.out.println();
6969
}
7070

71-
// Trade the Request Token and Verfier for the Access Token
72-
System.out.println("Trading the Request Token for an Access Token...");
71+
System.out.println("Trading the Authorization Code for an Access Token...");
7372
final OAuth2AccessToken accessToken = service.getAccessToken(code);
7473
System.out.println("Got the Access Token!");
7574
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");

‎scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public static void main(String... args) throws IOException, InterruptedException
5858
System.out.println();
5959
}
6060

61-
// Trade the Request Token and Verfier for the Access Token
62-
System.out.println("Trading the Request Token for an Access Token...");
61+
System.out.println("Trading the Authorization Code for an Access Token...");
6362
final OAuth2AccessToken accessToken = service.getAccessToken(code);
6463
System.out.println("Got the Access Token!");
6564
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");

‎scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public static void main(String... args) throws IOException, ExecutionException,
6161
System.out.println();
6262
}
6363

64-
// Trade the Request Token and Verfier for the Access Token
65-
System.out.println("Trading the Request Token for an Access Token...");
64+
System.out.println("Trading the Authorization Code for an Access Token...");
6665
OAuth2AccessToken accessToken = service.getAccessToken(code);
6766
System.out.println("Got the Access Token!");
6867
System.out.println("(if your curious it looks like this: " + accessToken

0 commit comments

Comments
 (0)