summaryrefslogtreecommitdiff
path: root/src/support/ConsumerKeySecret.java
blob: 25bde51534b7f3bbbedbe5275c244745c81709cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package support;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.Charsets;

/**
 * Container for a pair of consumer key and secret. See
 * https://dev.twitter.com/docs/auth/application-only-auth
 */
public class ConsumerKeySecret {

    private final String key;
    private final String secret;

    public ConsumerKeySecret(String key, String secret) {
        this.key = key;
        this.secret = secret;
    }

    public String getKey() {
        return key;
    }

    public String getSecret() {
        return secret;
    }

    private String getBearerToken() {
        return key + ":" + secret;
    }

    /**
     * @return Base64-encoded bearer token that can should be included in the
     * Authorization header for application-only requests.
     */
    public String getBearerTokenBase64() {
        return Base64.encodeBase64String(getBearerToken().getBytes(Charsets.UTF_8));
    }
}