OAuthParameters params = new OAuthParameters().consumerKey(input.oauthConsumerKey).signatureMethod("HMAC-SHA1").version("1.0"); OAuthSecrets secrets = new OAuthSecrets().consumerSecret(input.oauthConsumerSecret); client.addFilter(new OAuthClientFilter(client.getProviders(), params, secrets));
OAuthParameters params = new OAuthParameters(); params.readRequest(request); String consumerKey = params.getConsumerKey(); String timestampStr = params.getTimestamp(); if (timestampStr == null)
if (parameters.getToken() == null) { parameters.token(token); secrets.tokenSecret(response.getFirst(OAuthParameters.TOKEN_SECRET)); state = State.REQUEST_TOKEN; parameters.verifier(handler.authorize(getAuthorizationUri())); return handle(request); } finally { if (state == State.UNMANAGED) { parameters.token(null); secrets.tokenSecret(null); if (parameters.getVerifier() == null) { throw new UnauthorizedRequestException(parameters, getAuthorizationUri()); parameters.token(token); secrets.tokenSecret(secret); handler.authorized(parameters.getToken(), secrets.getTokenSecret()); state = State.MANAGED; } finally { parameters.remove(OAuthParameters.VERIFIER); if (state == State.UNMANAGED) { parameters.token(null); secrets.tokenSecret(null); state = State.MANAGED; final OAuthParameters p = (OAuthParameters)parameters.clone(); // make modifications to clone if (p.getTimestamp() == null) {
if (parameters.getSignatureMethod() == null) { parameters.signatureMethod("HMAC-SHA1"); if (parameters.getVersion() == null) { parameters.version();
/** * Generates an OAuth signature for the given request, parameters and * secrets, and stores it as a signature parameter, and writes the * OAuth parameters to the request as an Authorization header. * * @param request the request to generate signature for and write header to. * @param params the OAuth authorization parameters. * @param secrets the secrets used to generate the OAuth signature. * @throws OAuthSignatureException if an error occurred generating the signature. */ public static void sign(OAuthRequest request, OAuthParameters params, OAuthSecrets secrets) throws OAuthSignatureException { params = (OAuthParameters)params.clone(); // don't modify caller's parameters params.setSignature(generate(request, params, secrets)); params.writeRequest(request); }
for (String key : params.keySet()) { String value = params.get(key); if (key.startsWith("oauth_") && params.containsKey(key)) { continue;
/** * Builder pattern method to return {@link OAuthParameters} after setting * nonce to a randomly-generated UUID. * * @return this parameters object. */ public OAuthParameters nonce() { setNonce(); return this; }
/** * Builder pattern method to return {@link OAuthParameters} after setting * timestamp to the current time. * * @return this parameters object. */ public OAuthParameters timestamp() { setTimestamp(); return this; }
/** * Retrieves an instance of a signature method that can be used to generate * or verify signatures for data. * * @return the retrieved signatured method. * @throws UnsupportedSignatureMethodException if signature method not supported. */ private static OAuthSignatureMethod getSignatureMethod(OAuthParameters params) throws UnsupportedSignatureMethodException { OAuthSignatureMethod method = Methods.getInstance(params.getSignatureMethod()); if (method == null) { throw new UnsupportedSignatureMethodException(params.getSignatureMethod()); } return method; }
/** * Generates an OAuth signature for the given request, parameters and * secrets, and stores it as a signature parameter, and writes the * OAuth parameters to the request as an Authorization header. * * @param request the request to generate signature for and write header to. * @param params the OAuth authorization parameters. * @param secrets the secrets used to generate the OAuth signature. * @throws OAuthSignatureException if an error occurred generating the signature. */ public static void sign(OAuthRequest request, OAuthParameters params, OAuthSecrets secrets) throws OAuthSignatureException { params = (OAuthParameters)params.clone(); // don't modify caller's parameters params.setSignature(generate(request, params, secrets)); params.writeRequest(request); }
for (String key : params.keySet()) { String value = params.get(key); if (key.startsWith("oauth_") && params.containsKey(key)) { continue;
/** * Builder pattern method to return {@link OAuthParameters} after setting * nonce. * * @param nonce a value that should be unique for a given timestamp. * @return this parameters object. */ public OAuthParameters nonce(String nonce) { setNonce(nonce); return this; }
/** * Builder pattern method to return {@link Parameters} after setting * timestamp. * * @param timestamp positive integer, typically number of seconds since epoch. * @return this parameters object. */ public OAuthParameters timestamp(String timestamp) { setTimestamp(timestamp); return this; }
/** * Retrieves an instance of a signature method that can be used to generate * or verify signatures for data. * * @return the retrieved signatured method. * @throws UnsupportedSignatureMethodException if signature method not supported. */ private static OAuthSignatureMethod getSignatureMethod(OAuthParameters params) throws UnsupportedSignatureMethodException { OAuthSignatureMethod method = Methods.getInstance(params.getSignatureMethod()); if (method == null) { throw new UnsupportedSignatureMethodException(params.getSignatureMethod()); } return method; } }
OAuthParameters params = new OAuthParameters().consumerKey(input.oauthConsumerKey).signatureMethod("HMAC-SHA1").version("1.0"); OAuthSecrets secrets = new OAuthSecrets().consumerSecret(input.oauthConsumerSecret); client.addFilter(new OAuthClientFilter(client.getProviders(), params, secrets));
/** * Builder pattern method to return {@link Parameters} after setting * nonce. * * @param nonce a value that should be unique for a given timestamp. * @return this parameters object. */ public OAuthParameters nonce(String nonce) { setNonce(nonce); return this; }
/** * Builder pattern method to return {@link OAuthParameters} after setting * timestamp. * * @param timestamp positive integer, typically number of seconds since epoch. * @return this parameters object. */ public OAuthParameters timestamp(String timestamp) { setTimestamp(timestamp); return this; }
/** * Builder pattern method to return {@link Parameters} after setting * nonce to a randomly-generated UUID. * * @param nonce a value that should be unique for a given timestamp. * @return this parameters object. */ public OAuthParameters nonce() { setNonce(); return this; }