/** * Create a new builder instance. * * @param consumerCredentials Consumer credentials. */ OAuth1BuilderImpl(final ConsumerCredentials consumerCredentials) { this(new OAuth1Parameters(), new OAuth1Secrets(), consumerCredentials); }
/** * Verifies the OAuth signature for a given request, parameters and * secrets. * * @param request the request to verify the signature from. * @param params the OAuth authorization parameters * @param secrets the secrets used to verify the OAuth signature. * @return true if the signature is verified. * @throws OAuth1SignatureException if an error occurred generating the signature. */ public boolean verify(final OAuth1Request request, final OAuth1Parameters params, final OAuth1Secrets secrets) throws OAuth1SignatureException { return getSignatureMethod(params).verify(baseString(request, params), secrets, params.getSignature()); }
/** * Generates and returns an OAuth signature for the given request, * parameters and secrets. * * @param request the request to generate signature for. * @param params the OAuth authorization parameters. * @param secrets the secrets used to generate the OAuth signature. * @return the OAuth digital signature. * @throws OAuth1SignatureException if an error occurred generating the signature. */ public String generate(final OAuth1Request request, final OAuth1Parameters params, final OAuth1Secrets secrets) throws OAuth1SignatureException { return getSignatureMethod(params).sign(baseString(request, params), secrets); }
/** * Returns the protection realm for the request. */ public String getRealm() { return get(REALM); }
/** * Builder pattern method to return {@link OAuth1Secrets} after setting * consumer secret. * * @param tokenSecret the token secret. */ public OAuth1Secrets tokenSecret(String tokenSecret) { setTokenSecret(tokenSecret); return this; }
/** * Builder pattern method to return {@code OAuth1Parameters} after setting * token. * * @param token the access or request token. * @return this parameters object. */ public OAuth1Parameters token(String token) { setToken(token); return this; }
/** * Builder pattern method to return {@code OAuth1Parameters} after setting * nonce to a randomly-generated UUID. * * @return this parameters object. */ public OAuth1Parameters nonce() { setNonce(); return this; }
/** * Builder pattern method to return {@code OAuth1Parameters} after setting * consumer key. * * @param consumerKey the consumer key. */ public OAuth1Parameters consumerKey(String consumerKey) { setConsumerKey(consumerKey); return this; }
/** * Builder pattern method to return {@code OAuth1Parameters} after setting * signature method. * * @param signatureMethod the signature method used to sign the request. * @return this parameters object. */ public OAuth1Parameters signatureMethod(String signatureMethod) { setSignatureMethod(signatureMethod); return this; }
/** * Sets the timestamp. Its value is not validated, but should be a * positive integer, typically containing the number of seconds since * January 1, 1970 00:00:00 GMT (epoch). */ public void setTimestamp(String timestamp) { put(TIMESTAMP, timestamp); }
/** * Converts a byte array into a Base64 encoded string. * * @param data bytes to encode. * @return base64 encoding of data; 4 chars for every 3 bytes. */ public static String encode(byte[] data) { return encode(data, 0, data.length); }
/** * Builder pattern method to return {@code OAuth1Parameters} after setting * signature. * * @param signature the signature for the request. * @return this parameters object. */ public OAuth1Parameters signature(String signature) { setSignature(signature); return this; }
/** * Returns the consumer key. */ public String getConsumerKey() { return get(CONSUMER_KEY); }
/** * Sets the callback URL. */ public void setCallback(String callback) { put(CALLBACK, callback); }
/** * Returns the timestamp, a value expected to be a positive integer, * typically containing the number of seconds since January 1, 1970 * 00:00:00 GMT (epoch). */ public String getTimestamp() { return get(TIMESTAMP); }
/** * Sets the protection realm for the request. */ public void setRealm(String realm) { put(REALM, realm); }
/** * Returns the signature method used to sign the request. */ public String getSignatureMethod() { return get(SIGNATURE_METHOD); }
/** * Returns the nonce, a value that should be unique for a given * timestamp. */ public String getNonce() { return get(NONCE); }
/** * Returns the verifier code. */ public String getVerifier() { return get(VERIFIER); }