X Tutup
Skip to content

Commit ba12ff6

Browse files
committed
Uncapsulate base64 implementation details. (only java8 Base64 implementation is still available at the moment)
1 parent 450977a commit ba12ff6

File tree

16 files changed

+202
-1042
lines changed

16 files changed

+202
-1042
lines changed

changelog

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[SNAPSHOT]
22
* add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens
3+
* make Base64 en/de-coding not dependent from java8 implementation (use three optional implementation
4+
(internal java 8+, Apache Commons Codec, JAXB) detected in runtime) (thanks to https://github.com/CodingFabian)
35

46
[8.1.0]
57
* add raw Response (with HTTP response code and body) as member to the OAuth2AccessTokenErrorResponse
@@ -61,7 +63,8 @@
6163

6264
[6.4.1]
6365
* support TLS 1.3 in JDK 11 for Salesforce
64-
* fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik)
66+
* fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code)
67+
(thanks to https://github.com/SainagNeelamPatnaik)
6568
* separate OAuth1.0a and OAuth2.0 classes
6669

6770
[6.3.0]
@@ -73,26 +76,31 @@
7376
and it should be set per request, not per created OAuthService
7477

7578
[6.2.0]
76-
* add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic)
79+
* add new API Microsoft Azure Active Directory (Azure AD) 2.0
80+
(thanks to https://github.com/rzukow and https://github.com/dgrudenic)
7781

7882
[6.1.0]
7983
* add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic)
8084
* add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni)
8185

8286
[6.0.0]
8387
* make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove)
84-
* switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions.
88+
* switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+.
89+
Complement README with links and RFC descriptions.
8590
* switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible
8691
* add new API Wunderlist (https://www.wunderlist.com/) (thanks to https://github.com/M-F-K)
8792

8893
[5.6.0]
89-
* remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn)
94+
* remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/)
95+
(thanks to https://github.com/zawn)
9096
* add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3)
9197
* switch OAuth2 ClientAuthenticationType from enum to interface ClientAuthentication to be extensible according to
9298
https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn)
93-
* add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314)
99+
* add RuntimeException processing in async http clients (delivered to onError callbacks)
100+
(thanks to https://github.com/jochen314)
94101
* check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314)
95-
* fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix)
102+
* fix case sensitive Http Headers comparison and sending Content-Type header along with content-type
103+
(thanks to https://github.com/marnix)
96104
* add HiOrg-Server (https://www.hiorg-server.de/) API (thanks to https://github.com/MartinBoehmer)
97105

98106
[5.5.0]
@@ -105,7 +113,8 @@
105113
* fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef)
106114
* add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen)
107115
* add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib)
108-
* add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered)
116+
* add new API - Fitbit (https://www.fitbit.com/)
117+
(thanks to https://github.com/JustinLawler and https://github.com/alexthered)
109118
* deprecate OAuthConfig
110119
* OAuth1.0: send "oob" instead of null callback while requesting RequestToken (thanks to https://github.com/Rafaelsk)
111120

@@ -119,7 +128,8 @@
119128
* add required param version to VK ВКонтакте (http://vk.com/) urls
120129

121130
[5.2.0-java7again]
122-
* allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit)
131+
* allow 'null' as callback. It's an optional parameter. Remove "oob" as default
132+
(thanks to https://github.com/massongit)
123133
* java7 compatible again!
124134

125135
[5.1.0]
@@ -132,17 +142,20 @@
132142
* drop Java 7 backward compatibility support, become Java 8 only (was reverted in v5.2.0-java7again)
133143
* add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv)
134144
* add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv)
135-
* add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango)
145+
* add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients)
146+
(thanks for suggesting to https://github.com/dieseldjango)
136147
* switch to use HTTP Basic Authorization by default in requests with need of
137148
(2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class
138149
* add support for client_credentials grant type (thanks to https://github.com/vivin)
139150
* add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin)
140151
* add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object.
141152
Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now.
142-
* drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa)
153+
* drop toString method from *Tokens to prevent leak of sensible data (token ans secrets)
154+
(thanks to https://github.com/rcaa)
143155
* add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb)
144156
* add support for appsecret_proof in Facebook
145-
* update Facebook v2.8 -> v2.11 (version can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11"))
157+
* update Facebook v2.8 -> v2.11
158+
(version can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11"))
146159

147160
[4.2.0]
148161
* DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73)
@@ -155,21 +168,27 @@
155168
* update Live API (thanks to https://github.com/typhoon17)
156169

157170
[4.1.1]
158-
* omit the client_secret parameter if it is an empty string while refreshing token (thanks to https://github.com/KungfuPancake)
171+
* omit the client_secret parameter if it is an empty string while refreshing token
172+
(thanks to https://github.com/KungfuPancake)
159173
* allow perms to be specified in Flickr Api (read, write, or delete) (thanks to https://github.com/rogerhu)
160-
* OdnoklassnikiService should consider params in a body while signing the request (thanks to https://github.com/MrNeuronix)
174+
* OdnoklassnikiService should consider params in a body while signing the request
175+
(thanks to https://github.com/MrNeuronix)
161176
* do not open OutputStream for output while sending empty body in HTTP requests in the default JDK Http client
162177

163178
[4.1.0]
164-
* make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs)
179+
* make client_secret optional in OAuth2 while requesting AccessToken
180+
(if set to null, it's not required by OAuth2 specs)
165181
* move OAuth1 SignatureType from ServiceBuilder to API
166182
* add body for PATCH HTTP method
167-
* make addOAuthParams appendSignature methods protected in OAuth10aService (to override them in case of need) (thanks to https://github.com/vivin)
183+
* make addOAuthParams appendSignature methods protected in OAuth10aService (to override them in case of need)
184+
(thanks to https://github.com/vivin)
168185

169186
[4.0.0]
170-
* Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async. Move default Http engine to JDKHttpClient.
187+
* Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async.
188+
Move default Http engine to JDKHttpClient.
171189
* introduce SignatureType for OAuth2.0 to implement Bearer signing for the requests
172-
* switch Google, GitHub, Facebook OAuth2.0 oauth requests signing to more secured recommended variant (GET-param -> header Bearer)
190+
* switch Google, GitHub, Facebook OAuth2.0 oauth requests signing to more secured recommended variant
191+
(GET-param -> header Bearer)
173192
* introduce custom nonstandard Facebook AccessTokenErrorResponse
174193

175194
[3.4.1]
@@ -182,14 +201,16 @@
182201
* add support for byte[] and File (async only) payload in OAuth Requests (thanks to https://github.com/keijohyttinen)
183202
* add support for HTTP verbs (thanks to https://github.com/keijohyttinen)
184203
* add OkHttp http client support (thanks to https://github.com/arcao)
185-
* add default HTTP client configs (to use like 'new ServiceBuilder().httpClientConfig(OkHttpHttpClientConfig.defaultConfig())')
204+
* add default HTTP client configs
205+
(to use like 'new ServiceBuilder().httpClientConfig(OkHttpHttpClientConfig.defaultConfig())')
186206
* you can use your own impl of AsyncHttpClient
187207

188208
[3.3.0]
189209
* update Facebook v2.6 -> v2.8
190210
* add The Things Network API (v1-staging and v2-preview) (thanks to https://github.com/jpmeijers)
191211
* add Box (thanks to https://github.com/MclaughlinSteve)
192-
* fix: OAuth20Service::refreshAccessToken should use RefreshTokenEndpoint, not AccessTokenEndpoint (thanks to https://github.com/vivin)
212+
* fix: OAuth20Service::refreshAccessToken should use RefreshTokenEndpoint, not AccessTokenEndpoint
213+
(thanks to https://github.com/vivin)
193214
* move signRequest method to OAuthService (common for OAuth1 and OAuth2) (thanks to https://github.com/apomelov)
194215
* drop deprecated setConnectionKeepAlive method
195216

@@ -198,14 +219,17 @@
198219
* handle OAuth2 error response for Issuing an Access Token (thanks to juherr)
199220

200221
[3.1.0]
201-
* fix OdnoklassnikiServiceImpl signature, params for hash must be sorted in lexicographic order, see http://new.apiok.ru/dev/methods/
222+
* fix OdnoklassnikiServiceImpl signature, params for hash must be sorted in lexicographic order,
223+
see http://new.apiok.ru/dev/methods/
202224
* add posibility to use externally created http client
203225
* make ScribeJava compilable under jdk7 (checkstyle downgraded for jdk 1.7)
204226
* add travis CI (check [oracle|open]jdk7 oraclejdk8)
205227

206228
[3.0.0]
207-
* create abstract HTTP Client layer to support different HTTP clients as plugins (AHC and Ning support becames maven submodules)
208-
* remove changing global JVM property http.keepAlive, deprecate controlling this property inside of ScribeJava (thanks to wldaunfr and rockihack)
229+
* create abstract HTTP Client layer to support different HTTP clients as plugins
230+
(AHC and Ning support becames maven submodules)
231+
* remove changing global JVM property http.keepAlive, deprecate controlling this property inside of ScribeJava
232+
(thanks to wldaunfr and rockihack)
209233

210234
[2.8.1]
211235
* add Salesforce sandbox API support
@@ -246,8 +270,10 @@
246270
[2.5.2]
247271
* add Google Async Exmaple (with bugfix for it to work)
248272
* add OSGI manifest metadata
249-
* apiSecret is not mandatory parameter in config (to use on client sides and other flows without need of the API secret)
250-
* implement OAuth2 Authorization Response parsing in the OAuth20Service (to extract code and state from url, useful for Android)
273+
* apiSecret is not mandatory parameter in config
274+
(to use on client sides and other flows without need of the API secret)
275+
* implement OAuth2 Authorization Response parsing in the OAuth20Service
276+
(to extract code and state from url, useful for Android)
251277
* update ok.ru API urls, add 'state' support, add refresh token to the example
252278

253279
[2.4.0]

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<modules>
1818
<module>scribejava-core</module>
19+
<module>scribejava-java8</module>
1920
<module>scribejava-apis</module>
2021
<module>scribejava-httpclient-ahc</module>
2122
<module>scribejava-httpclient-ning</module>

scribejava-core/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
<version>8.1.1-SNAPSHOT</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
11-
11+
1212
<groupId>com.github.scribejava</groupId>
1313
<artifactId>scribejava-core</artifactId>
1414
<name>ScribeJava Core</name>
1515
<packaging>jar</packaging>
1616

17+
<dependencies>
18+
<dependency>
19+
<groupId>com.github.scribejava</groupId>
20+
<artifactId>scribejava-java8</artifactId>
21+
<version>${project.version}</version>
22+
</dependency>
23+
</dependencies>
24+
1725
<build>
1826
<plugins>
1927
<plugin>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.github.scribejava.core.base64;
2+
3+
public abstract class Base64 {
4+
5+
private static volatile Base64 instance;
6+
7+
public static Base64 getInstance() {
8+
Base64 localInstance = instance;
9+
if (localInstance == null) {
10+
synchronized (Base64.class) {
11+
localInstance = instance;
12+
if (localInstance == null) {
13+
localInstance = createInstance();
14+
instance = localInstance;
15+
}
16+
}
17+
}
18+
return localInstance;
19+
}
20+
21+
private static Base64 createInstance() {
22+
return new Java8Base64();
23+
}
24+
25+
public static void init(Base64 base64) {
26+
synchronized (Base64.class) {
27+
instance = base64;
28+
}
29+
}
30+
31+
public static String encode(byte[] bytes) {
32+
return getInstance().internalEncode(bytes);
33+
}
34+
35+
public static String encodeUrlWithoutPadding(byte[] bytes) {
36+
return getInstance().internalEncodeUrlWithoutPadding(bytes);
37+
}
38+
39+
public static byte[] decodeMime(String string) {
40+
return getInstance().internalDecodeMime(string);
41+
}
42+
43+
protected abstract String internalEncode(byte[] bytes);
44+
45+
protected abstract String internalEncodeUrlWithoutPadding(byte[] bytes);
46+
47+
protected abstract byte[] internalDecodeMime(String string);
48+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.scribejava.core.base64;
2+
3+
public class Java8Base64 extends Base64 {
4+
5+
private static final com.github.scribejava.java8.base64.Java8Base64 JAVA8_BASE64
6+
= new com.github.scribejava.java8.base64.Java8Base64();
7+
8+
@Override
9+
protected String internalEncode(byte[] bytes) {
10+
return JAVA8_BASE64.internalEncode(bytes);
11+
}
12+
13+
@Override
14+
protected String internalEncodeUrlWithoutPadding(byte[] bytes) {
15+
return JAVA8_BASE64.internalEncodeUrlWithoutPadding(bytes);
16+
}
17+
18+
@Override
19+
protected byte[] internalDecodeMime(String string) {
20+
return JAVA8_BASE64.internalDecodeMime(string);
21+
}
22+
23+
}

0 commit comments

Comments
 (0)
X Tutup