OAuthParameters params = new OAuthParameters().signatureMethod("HMAC-SHA1"). consumerKey("consumerKey").version("1.1"); OAuthSecrets secrets = new OAuthSecrets().consumerSecret("secretKey"); OAuthClientFilter filter = new OAuthClientFilter(client().getProviders(), params, secrets); WebResource webResource = resource(); webResource.addFilter(filter); String responseMsg = webResource.path("oauth").get(String.class);
@Path("oauth") public class OAuthService { @GET @Produces("text/html") public String secretService(@Context HttpContext httpContext) { OAuthServerRequest request = new OAuthServerRequest(httpContext.getRequest()); OAuthParameters params = new OAuthParameters(); params.readRequest(request); OAuthSecrets secrets = new OAuthSecrets().consumerSecret("secretKey"); try { if(!OAuthSignature.verify(request, params, secrets)) return "false"; } catch (OAuthSignatureException ose) { return "false"; } return "OK"; } }
OAuthParameters oauthParameters; try { oauthParameters = new OAuthParameters(); oauthParameters.consumerKey = clientId; oauthParameters.signer = oauthParameters.version = "1.0"; oauthParameters.computeNonce(); oauthParameters.computeTimestamp(); oauthParameters.computeSignature(requestMethod, new GenericUrl(requestUrl)); } catch (GeneralSecurityException e) { throw new OAuthAuthenticationException(e); return oauthParameters.getAuthorizationHeader();
OAuthSecrets secrets = new OAuthSecrets() .consumerSecret(consumerSecret); OAuthParameters authParams = new OAuthParameters() .consumerKey(consumerKey).signatureMethod(HMAC_SHA1.NAME) .version(AuthenticationConstants.OAUTH_VERSION_10A) authParams = authParams.callback(callback); authParams = authParams.verifier(verifier); authParams = authParams.token(token);
public class OAuthAuthenticationFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { // Read the OAuth parameters from the request OAuthServerRequest request = new OAuthServerRequest(containerRequest); OAuthParameters params = new OAuthParameters(); params.readRequest(request); // Set the secret(s), against which we will verify the request OAuthSecrets secrets = new OAuthSecrets(); // ... secret setting code ... // Check that the timestamp has not expired String timestampStr = params.getTimestamp(); // ... timestamp checking code ... // Verify the signature try { if(!OAuthSignature.verify(request, params, secrets)) { throw new WebApplicationException(401); } } catch (OAuthSignatureException e) { throw new WebApplicationException(e, 401); } // Return the request return containerRequest; } }
public void intercept(HttpRequest request) throws IOException { authorizer.intercept(request); }
public void initialize(HttpRequest request) throws IOException { authorizer.initialize(request); request.setUnsuccessfulResponseHandler(this); }
public void intercept(HttpRequest request) throws IOException { authorizer.intercept(request); }
public void initialize(HttpRequest request) throws IOException { authorizer.initialize(request); request.setUnsuccessfulResponseHandler(this); }
private void postConstruct() { OAuthHmacSigner signer = new OAuthHmacSigner(); signer.clientSharedSecret = sharedSecret; signer.tokenSharedSecret = tokenSharedSecret; authorizer = new OAuthParameters(); authorizer.consumerKey = consumerKey; authorizer.signer = signer; authorizer.token = token; }
@SuppressWarnings("deprecation") public void intercept(HttpRequest request) throws IOException { request.url.set("xoauth_requestor_id", requestorId); if (parameters != null) { parameters.intercept(request); } }
private void postConstruct() { OAuthHmacSigner signer = new OAuthHmacSigner(); signer.clientSharedSecret = sharedSecret; signer.tokenSharedSecret = tokenSharedSecret; authorizer = new OAuthParameters(); authorizer.consumerKey = consumerKey; authorizer.signer = signer; authorizer.token = token; }
/** * Revokes the long-lived access token. * * @param parameters OAuth parameters * @throws IOException I/O exception * @since 1.3 */ public static void revokeAccessToken(HttpTransport transport, OAuthParameters parameters) throws IOException { HttpRequest request = transport.createRequestFactory().buildGetRequest( new GenericUrl("https://www.google.com/accounts/AuthSubRevokeToken")); parameters.intercept(request); request.execute().ignore(); } }
OAuthParameters oauthParameters = new OAuthParameters(); signer.tokenSharedSecret = accessTokenResponse.tokenSecret; oauthParameters.signer = signer;
OAuthHmacSigner signer = new OAuthHmacSigner(); HttpTransport httpTransport = new NetHttpTransport(); OAuthParameters oauthParameters = new OAuthParameters(); final ArrayMap<String, Object> customKeys = new ArrayMap<String, Object>();
Providers providers = this.client.getProviders(); OAuthSecrets secrets = new OAuthSecrets().consumerSecret(oAuthConsumerSecret); OAuthParameters params = new OAuthParameters().consumerKey(oAuthConsumerKey).signatureMethod("HMAC-SHA1"); OAuthClientFilter filter = new OAuthClientFilter(providers,params,secrets);