Package oauth.signpost
Class OAuth
- java.lang.Object
-
- oauth.signpost.OAuth
-
public class OAuth extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringENCODINGstatic StringFORM_ENCODEDstatic StringHTTP_AUTHORIZATION_HEADERstatic StringOAUTH_CALLBACKstatic StringOAUTH_CALLBACK_CONFIRMEDstatic StringOAUTH_CONSUMER_KEYstatic StringOAUTH_NONCEstatic StringOAUTH_SIGNATUREstatic StringOAUTH_SIGNATURE_METHODstatic StringOAUTH_TIMESTAMPstatic StringOAUTH_TOKENstatic StringOAUTH_TOKEN_SECRETstatic StringOAUTH_VERIFIERstatic StringOAUTH_VERSIONstatic StringOUT_OF_BANDPass this value as the callback "url" upon retrieving a request token if your application cannot receive callbacks (e.g.static StringVERSION_1_0
-
Constructor Summary
Constructors Constructor Description OAuth()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringaddQueryParameters(String url, String... kvPairs)Appends a list of key/value pairs to the given URL, e.g.:static StringaddQueryParameters(String url, Map<String,String> params)static StringaddQueryString(String url, String queryString)static voiddebugOut(String key, String value)static HttpParametersdecodeForm(InputStream content)static HttpParametersdecodeForm(String form)Parse a form-urlencoded document.static <T extends Map.Entry<String,String>>
StringformEncode(Collection<T> parameters)Construct a x-www-form-urlencoded document containing the given sequence of name/value pairs.static <T extends Map.Entry<String,String>>
voidformEncode(Collection<T> parameters, OutputStream into)Construct a x-www-form-urlencoded document containing the given sequence of name/value pairs.static booleanisEmpty(String str)static HttpParametersoauthHeaderToParamsMap(String oauthHeader)static StringpercentDecode(String s)static StringpercentEncode(String s)static StringprepareOAuthHeader(String... kvPairs)Builds an OAuth header from the given list of header fields.static StringsafeToString(Object from)static StringtoHeaderElement(String name, String value)Helper method to concatenate a parameter and its value to a pair that can be used in an HTTP header.static <T extends Map.Entry<String,String>>
Map<String,String>toMap(Collection<T> from)Construct a Map containing a copy of the given parameters.
-
-
-
Field Detail
-
VERSION_1_0
public static final String VERSION_1_0
- See Also:
- Constant Field Values
-
ENCODING
public static final String ENCODING
- See Also:
- Constant Field Values
-
FORM_ENCODED
public static final String FORM_ENCODED
- See Also:
- Constant Field Values
-
HTTP_AUTHORIZATION_HEADER
public static final String HTTP_AUTHORIZATION_HEADER
- See Also:
- Constant Field Values
-
OAUTH_CONSUMER_KEY
public static final String OAUTH_CONSUMER_KEY
- See Also:
- Constant Field Values
-
OAUTH_TOKEN
public static final String OAUTH_TOKEN
- See Also:
- Constant Field Values
-
OAUTH_TOKEN_SECRET
public static final String OAUTH_TOKEN_SECRET
- See Also:
- Constant Field Values
-
OAUTH_SIGNATURE_METHOD
public static final String OAUTH_SIGNATURE_METHOD
- See Also:
- Constant Field Values
-
OAUTH_SIGNATURE
public static final String OAUTH_SIGNATURE
- See Also:
- Constant Field Values
-
OAUTH_TIMESTAMP
public static final String OAUTH_TIMESTAMP
- See Also:
- Constant Field Values
-
OAUTH_NONCE
public static final String OAUTH_NONCE
- See Also:
- Constant Field Values
-
OAUTH_VERSION
public static final String OAUTH_VERSION
- See Also:
- Constant Field Values
-
OAUTH_CALLBACK
public static final String OAUTH_CALLBACK
- See Also:
- Constant Field Values
-
OAUTH_CALLBACK_CONFIRMED
public static final String OAUTH_CALLBACK_CONFIRMED
- See Also:
- Constant Field Values
-
OAUTH_VERIFIER
public static final String OAUTH_VERIFIER
- See Also:
- Constant Field Values
-
OUT_OF_BAND
public static final String OUT_OF_BAND
Pass this value as the callback "url" upon retrieving a request token if your application cannot receive callbacks (e.g. because it's a desktop app). This will tell the service provider that verification happens out-of-band, which basically means that it will generate a PIN code (the OAuth verifier) and display that to your user. You must obtain this code from your user and pass it toOAuthProvider#retrieveAccessToken(OAuthConsumer, String)in order to complete the token handshake.- See Also:
- Constant Field Values
-
-
Method Detail
-
formEncode
public static <T extends Map.Entry<String,String>> void formEncode(Collection<T> parameters, OutputStream into) throws IOException
Construct a x-www-form-urlencoded document containing the given sequence of name/value pairs. Use OAuth percent encoding (not exactly the encoding mandated by x-www-form-urlencoded).- Throws:
IOException
-
formEncode
public static <T extends Map.Entry<String,String>> String formEncode(Collection<T> parameters) throws IOException
Construct a x-www-form-urlencoded document containing the given sequence of name/value pairs. Use OAuth percent encoding (not exactly the encoding mandated by x-www-form-urlencoded).- Throws:
IOException
-
decodeForm
public static HttpParameters decodeForm(String form)
Parse a form-urlencoded document.
-
decodeForm
public static HttpParameters decodeForm(InputStream content) throws IOException
- Throws:
IOException
-
toMap
public static <T extends Map.Entry<String,String>> Map<String,String> toMap(Collection<T> from)
Construct a Map containing a copy of the given parameters. If several parameters have the same name, the Map will contain the first value, only.
-
isEmpty
public static boolean isEmpty(String str)
-
addQueryParameters
public static String addQueryParameters(String url, String... kvPairs)
Appends a list of key/value pairs to the given URL, e.g.:String url = OAuth.addQueryParameters("http://example.com?a=1", b, 2, c, 3);which yields:http://example.com?a=1&b=2&c=3
All parameters will be encoded according to OAuth's percent encoding rules.- Parameters:
url- the URLkvPairs- the list of key/value pairs- Returns:
-
prepareOAuthHeader
public static String prepareOAuthHeader(String... kvPairs)
Builds an OAuth header from the given list of header fields. All parameters starting in 'oauth_*' will be percent encoded.String authHeader = OAuth.prepareOAuthHeader("realm", "http://example.com", "oauth_token", "x%y");which yields:OAuth realm="http://example.com", oauth_token="x%25y"
- Parameters:
kvPairs- the list of key/value pairs- Returns:
- a string eligible to be used as an OAuth HTTP Authorization header.
-
oauthHeaderToParamsMap
public static HttpParameters oauthHeaderToParamsMap(String oauthHeader)
-
toHeaderElement
public static String toHeaderElement(String name, String value)
Helper method to concatenate a parameter and its value to a pair that can be used in an HTTP header. This method percent encodes both parts before joining them.- Parameters:
name- the OAuth parameter name, e.g. oauth_tokenvalue- the OAuth parameter value, e.g. 'hello oauth'- Returns:
- a name/value pair, e.g. oauth_token="hello%20oauth"
-
-