|
12 | 12 | * in it's part 2.3.1. Client Password<br> |
13 | 13 | * https://tools.ietf.org/html/rfc6749#section-2.3.1 |
14 | 14 | */ |
15 | | -public enum ClientAuthenticationType { |
16 | | - HTTP_BASIC_AUTHENTICATION_SCHEME { |
17 | | - private final Base64.Encoder base64Encoder = Base64.getEncoder(); |
| 15 | +public abstract class ClientAuthenticationType { |
18 | 16 |
|
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( |
24 | 27 | 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 | + }; |
37 | 44 |
|
38 | | - public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); |
| 45 | + public abstract void addClientAuthentication(OAuthRequest request, String apiKey, |
| 46 | + String apiSecret); |
39 | 47 | } |
0 commit comments