X Tutup
Skip to content

Commit cca662c

Browse files
committed
1 parent 443c243 commit cca662c

File tree

11 files changed

+233
-229
lines changed

11 files changed

+233
-229
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ ScribeJava support out-of-box several HTTP clients:
8787
* Misfit (http://misfit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java)
8888
* NAVER (http://www.naver.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java)
8989
* Odnoklassniki Одноклассники (http://ok.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java)
90+
* Polar (https://www.polar.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java)
9091
* Pinterest (https://www.pinterest.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java)
9192
* 500px (https://500px.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java)
9293
* Renren (http://renren.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java)

changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[SNAPSHOT]
2+
* Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42)
3+
14
[6.9.0]
25
* Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen)
36

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.github.scribejava.apis;
2+
3+
import com.github.scribejava.apis.polar.PolarJsonTokenExtractor;
4+
import com.github.scribejava.apis.polar.PolarOAuthService;
5+
import com.github.scribejava.core.builder.api.DefaultApi20;
6+
import com.github.scribejava.core.extractors.TokenExtractor;
7+
import com.github.scribejava.core.httpclient.HttpClient;
8+
import com.github.scribejava.core.httpclient.HttpClientConfig;
9+
import com.github.scribejava.core.model.OAuth2AccessToken;
10+
11+
import java.io.OutputStream;
12+
13+
/**
14+
* Polar's OAuth2 client's implementation source: https://www.polar.com/accesslink-api/#authentication
15+
*/
16+
public class PolarAPI extends DefaultApi20 {
17+
18+
protected PolarAPI() {
19+
}
20+
21+
private static class InstanceHolder {
22+
23+
private static final PolarAPI INSTANCE = new PolarAPI();
24+
}
25+
26+
public static PolarAPI instance() {
27+
return PolarAPI.InstanceHolder.INSTANCE;
28+
}
29+
30+
@Override
31+
public String getAccessTokenEndpoint() {
32+
return "https://polarremote.com/v2/oauth2/token";
33+
}
34+
35+
@Override
36+
protected String getAuthorizationBaseUrl() {
37+
return "https://flow.polar.com/oauth2/authorization";
38+
}
39+
40+
@Override
41+
public PolarOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope,
42+
String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig,
43+
HttpClient httpClient) {
44+
45+
return new PolarOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream,
46+
userAgent, httpClientConfig, httpClient);
47+
}
48+
49+
@Override
50+
public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() {
51+
return PolarJsonTokenExtractor.instance();
52+
}
53+
}

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

Lines changed: 0 additions & 54 deletions
This file was deleted.

scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public static PolarJsonTokenExtractor instance() {
2525
}
2626

2727
@Override
28-
protected PolarOauth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn,
28+
protected PolarOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn,
2929
String refreshToken, String scope, JsonNode response, String rawResponse) {
30-
return new PolarOauth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
30+
return new PolarOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
3131
response.get("x_user_id").asText(), rawResponse);
3232
}
3333

scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.github.scribejava.apis.polar;
2+
3+
import com.github.scribejava.core.model.OAuth2AccessToken;
4+
5+
import java.util.Objects;
6+
7+
public class PolarOAuth2AccessToken extends OAuth2AccessToken {
8+
9+
private final String userId;
10+
11+
public PolarOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken,
12+
String scope, String userId, String rawResponse) {
13+
super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse);
14+
this.userId = userId;
15+
}
16+
17+
public String getUserId() {
18+
return userId;
19+
}
20+
21+
@Override
22+
public int hashCode() {
23+
int hash = super.hashCode();
24+
hash = 37 * hash + Objects.hashCode(userId);
25+
return hash;
26+
}
27+
28+
@Override
29+
public boolean equals(Object obj) {
30+
if (this == obj) {
31+
return true;
32+
}
33+
if (obj == null) {
34+
return false;
35+
}
36+
if (getClass() != obj.getClass()) {
37+
return false;
38+
}
39+
if (!super.equals(obj)) {
40+
return false;
41+
}
42+
43+
return Objects.equals(userId, ((PolarOAuth2AccessToken) obj).getUserId());
44+
}
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.github.scribejava.apis.polar;
2+
3+
import com.github.scribejava.core.builder.api.DefaultApi20;
4+
import com.github.scribejava.core.httpclient.HttpClient;
5+
import com.github.scribejava.core.httpclient.HttpClientConfig;
6+
import com.github.scribejava.core.model.OAuthConstants;
7+
import com.github.scribejava.core.model.OAuthRequest;
8+
import com.github.scribejava.core.oauth.AccessTokenRequestParams;
9+
import com.github.scribejava.core.oauth.OAuth20Service;
10+
import com.github.scribejava.core.pkce.PKCE;
11+
12+
import java.io.OutputStream;
13+
14+
public class PolarOAuthService extends OAuth20Service {
15+
16+
public PolarOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope,
17+
String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig,
18+
HttpClient httpClient) {
19+
super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig,
20+
httpClient);
21+
}
22+
23+
@Override
24+
protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) {
25+
final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint());
26+
27+
getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret());
28+
29+
request.addParameter(OAuthConstants.CODE, params.getCode());
30+
final String callback = getCallback();
31+
if (callback != null) {
32+
request.addParameter(OAuthConstants.REDIRECT_URI, callback);
33+
}
34+
request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE);
35+
36+
final String pkceCodeVerifier = params.getPkceCodeVerifier();
37+
if (pkceCodeVerifier != null) {
38+
request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier);
39+
}
40+
if (isDebug()) {
41+
log("created access token request with body params [%s], query string params [%s]",
42+
request.getBodyParams().asFormUrlEncodedString(),
43+
request.getQueryStringParams().asFormUrlEncodedString());
44+
}
45+
return request;
46+
}
47+
}

scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup