/** * Assembles request elements for which a digital signature is to be * generated/verified, per section 9.1.3 of the OAuth 1.0 specification. * * @param request the request from which to assemble elements. * @param params the OAuth authorization parameters from which to assemble elements. * @return the concetenated elements, ready to sign/verify */ private static String elements(OAuthRequest request, OAuthParameters params) throws OAuthSignatureException { StringBuffer buf = new StringBuffer(URLCodec.encode(request.getRequestMethod().toUpperCase())); buf.append('&').append(URLCodec.encode(constructRequestURL(request))); buf.append('&').append(URLCodec.encode(normalizeParameters(request, params))); return buf.toString(); }
/** * Writes the OAuth parameters to a request, as an Authorization header. * * @param request the request to write OAuth parameters to. * @return this parameters object. */ public OAuthParameters writeRequest(OAuthRequest request) { StringBuffer buf = new StringBuffer(SCHEME); boolean comma = false; for (String key : keySet()) { String value = get(key); if (value == null) { continue; } buf.append(comma ? ", " : " ").append(URLCodec.encode(key)); buf.append("=\"").append(URLCodec.encode(value)).append('"'); comma = true; } request.addHeaderValue(AUTHORIZATION_HEADER, buf.toString()); return this; } }