/** * 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; } }
for (String param : request.getParameterNames()) { if (!param.startsWith("oauth_")) { continue; List values = request.getParameterValues(param); if (values == null) { continue; List<String> headers = request.getHeaderValues(AUTHORIZATION_HEADER); if (headers == null) { return this; }
/** * 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(); }
for (String key : request.getParameterNames()) { List<String> values = request.getParameterValues(key);
/** * Constructs the request URL, per section 9.1.2 of the OAuth 1.0 * specification. * * @param request the incoming request construct URL from. * @return the constructed URL. */ private static String constructRequestURL(OAuthRequest request) throws OAuthSignatureException { URL url; try { url = new URL(request.getRequestURL()); } catch (MalformedURLException mue) { throw new OAuthSignatureException(mue); } StringBuffer buf = new StringBuffer(url.getProtocol()).append("://").append(url.getHost().toLowerCase()); int port = url.getPort(); if (port > 0 && port != url.getDefaultPort()) { buf.append(':').append(port); } buf.append(url.getPath()); return buf.toString(); }
for (String key : request.getParameterNames()) { List<String> values = request.getParameterValues(key);
/** * Constructs the request URI, per section 9.1.2 of the OAuth 1.0 * specification. * * @param request the incoming request to construct the URI from. * @return the constructed URI. */ private static URI constructRequestURL(OAuthRequest request) throws OAuthSignatureException { try { URL url = request.getRequestURL(); if (url == null) throw new OAuthSignatureException(); StringBuffer buf = new StringBuffer(url.getProtocol()).append("://").append(url.getHost().toLowerCase()); int port = url.getPort(); if (port > 0 && port != url.getDefaultPort()) { buf.append(':').append(port); } buf.append(url.getPath()); return new URI(buf.toString()); } catch (URISyntaxException mue) { throw new OAuthSignatureException(mue); } }
for (String param : request.getParameterNames()) { if (!param.startsWith("oauth_")) { continue; List values = request.getParameterValues(param); if (values == null) { continue; List<String> headers = request.getHeaderValues(AUTHORIZATION_HEADER); if (headers == null) { return this; }
/** * 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 concatenated elements, ready to sign/verify */ private static String elements(OAuthRequest request, OAuthParameters params) throws OAuthSignatureException { // HTTP request method StringBuilder buf = new StringBuilder(request.getRequestMethod().toUpperCase()); // request URL, see section 3.4.1.2 http://tools.ietf.org/html/draft-hammer-oauth-10#section-3.4.1.2 buf.append('&').append(UriComponent.encode(constructRequestURL(request).toASCIIString(), UriComponent.Type.UNRESERVED)); // normalized request parameters, see section 3.4.1.3.2 http://tools.ietf.org/html/draft-hammer-oauth-10#section-3.4.1.3.2 buf.append('&').append(UriComponent.encode(normalizeParameters(request, params), UriComponent.Type.UNRESERVED)); 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) { StringBuilder buf = new StringBuilder(SCHEME); boolean comma = false; for (String key : keySet()) { String value = get(key); if (value == null) { continue; } buf.append(comma ? ", " : " ").append(UriComponent.encode(key, UriComponent.Type.UNRESERVED)); buf.append("=\"").append(UriComponent.encode(value, UriComponent.Type.UNRESERVED)).append('"'); comma = true; } request.addHeaderValue(AUTHORIZATION_HEADER, buf.toString()); return this; } }