Skip to content

Commit 6787f8c

Browse files
committed
Modify the enum as an abstract type, allowing custom implementations。
1 parent 7a635da commit 6787f8c

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,36 @@
1212
* in it's part 2.3.1. Client Password<br>
1313
* https://tools.ietf.org/html/rfc6749#section-2.3.1
1414
*/
15-
public enum ClientAuthenticationType {
16-
HTTP_BASIC_AUTHENTICATION_SCHEME {
17-
private final Base64.Encoder base64Encoder = Base64.getEncoder();
15+
public abstract class ClientAuthenticationType {
1816

19-
@Override
20-
public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) {
21-
if (apiKey != null && apiSecret != null) {
22-
request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' '
23-
+ base64Encoder.encodeToString(
17+
public static final ClientAuthenticationType HTTP_BASIC_AUTHENTICATION_SCHEME =
18+
new ClientAuthenticationType() {
19+
private final Base64.Encoder base64Encoder = Base64.getEncoder();
20+
21+
@Override
22+
public void addClientAuthentication(OAuthRequest request, String apiKey,
23+
String apiSecret) {
24+
if (apiKey != null && apiSecret != null) {
25+
request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' '
26+
+ base64Encoder.encodeToString(
2427
String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8"))));
25-
}
26-
}
27-
},
28-
REQUEST_BODY {
29-
@Override
30-
public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) {
31-
request.addParameter(OAuthConstants.CLIENT_ID, apiKey);
32-
if (apiSecret != null) {
33-
request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret);
34-
}
35-
}
36-
};
28+
}
29+
}
30+
};
31+
32+
public static final ClientAuthenticationType REQUEST_BODY =
33+
new ClientAuthenticationType() {
34+
35+
@Override
36+
public void addClientAuthentication(OAuthRequest request, String apiKey,
37+
String apiSecret) {
38+
request.addParameter(OAuthConstants.CLIENT_ID, apiKey);
39+
if (apiSecret != null) {
40+
request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret);
41+
}
42+
}
43+
};
3744

38-
public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret);
45+
public abstract void addClientAuthentication(OAuthRequest request, String apiKey,
46+
String apiSecret);
3947
}

0 commit comments

Comments
 (0)