List of usage examples for twitter4j.auth RequestToken RequestToken
public RequestToken(String token, String tokenSecret)
From source file:bluevia.OAuth.java
License:Apache License
private String oAuthTwitter(HttpServletRequest req, String step) { String oAuthUrl = "/index.jsp"; Properties prop = new Properties(); prop.setProperty("oauth.consumerKey", TwitterOAuth.consumer_key); prop.setProperty("oauth.consumerSecret", TwitterOAuth.consumer_secret); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(TwitterOAuth.consumer_key, TwitterOAuth.consumer_secret); try {//from w w w .j a v a2 s.c o m if (step.compareTo("1") == 0) { RequestToken requestToken = twitter .getOAuthRequestToken(Util.getCallbackDomain() + "/oauth?network=twitter&step=2"); req.getSession().setAttribute("request_key", requestToken.getToken()); req.getSession().setAttribute("request_secret", requestToken.getTokenSecret()); oAuthUrl = requestToken.getAuthenticationURL(); } else { String request_key = (String) req.getSession().getAttribute("request_key"); String request_secret = (String) req.getSession().getAttribute("request_secret"); String oauth_verifier = req.getParameter("oauth_verifier"); RequestToken requestToken = new RequestToken(request_key, request_secret); AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, oauth_verifier); UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); Util.addNetworkAccount(user.getEmail(), "TwitterAccount", Util.TwitterOAuth.consumer_key, Util.TwitterOAuth.consumer_secret, accessToken.getToken(), accessToken.getTokenSecret()); req.getSession().removeAttribute("request_key"); req.getSession().removeAttribute("request_secret"); oAuthUrl = "/settings.jsp"; } } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); logger.severe(e.getMessage()); } catch (Exception e) { e.printStackTrace(); logger.severe(e.getMessage()); } return oAuthUrl; }
From source file:com.tuncaysenturk.jira.plugins.compatibility.servlet.TwitterLoginServlet.java
private void twitterCallback(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> context) { if (null == req.getParameter("denied") && null != req.getParameter("oauth_verifier")) { String verifier = req.getParameter("oauth_verifier").toString(); PropertySet propSet = ComponentManager.getComponent(PropertiesManager.class).getPropertySet(); propSet.setString("accessTokenVerifier", verifier); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(propSet.getString("consumerKey"), propSet.getString("consumerSecret")); RequestToken requestToken = new RequestToken(propSet.getString("requestToken"), propSet.getString("requestTokenSecret")); propSet.remove("requestToken"); propSet.remove("requestTokenSecret"); try {//from w ww. j av a 2 s. c om AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier); propSet.setString("accessToken", accessToken.getToken()); propSet.setString("accessTokenSecret", accessToken.getTokenSecret()); User user = twitter.verifyCredentials(); logger.info(JTPConstants.LOG_PRE + "User :" + user.getScreenName() + " logged in successfully"); restartListener(req, resp, context); } catch (TwitterException e) { logger.error(JTPConstants.LOG_PRE + "Error while streaming", e); ExceptionMessagesUtil.addExceptionMessage("Error while streaming : ", e); } } else { logger.warn(JTPConstants.LOG_PRE + "User denied Twitter authorization, plugin will not work properly"); ExceptionMessagesUtil .addExceptionMessage("User denied Twitter authorization, plugin will not work properly"); } }
From source file:me.chester.myretweetedtweets.User.java
License:Apache License
public void finishAuthorization(String token, String tokenSecret) throws TwitterException { RequestToken requestToken = new RequestToken(token, tokenSecret); AccessToken accessToken = twitter.getOAuthAccessToken(requestToken); twitter.setOAuthAccessToken(accessToken); this.token = accessToken.getToken(); this.tokenSecret = accessToken.getTokenSecret(); }
From source file:net.nitram509.controller.TwitterCallbackHttpController.java
License:Open Source License
public AccessToken validateAndRetrieveTwitterAccessToken(Twitter twitter, String requestTokenStr, String oauth_verifier) throws TwitterException { RequestToken requestToken = new RequestToken(requestTokenStr, ""); assert requestToken.getToken() != null; assert requestToken.getTokenSecret() != null; return twitter.getOAuthAccessToken(requestToken, oauth_verifier); }
From source file:org.fenixedu.bennu.social.ui.controller.SocialCallbackController.java
License:Open Source License
@RequestMapping(value = "/twitter/callback", method = RequestMethod.GET) public String twitter(Model model, RedirectAttributes redirectAttrs, @RequestParam(value = "oauth_token", required = false) String oauthToken, @RequestParam(value = "oauth_verifier", required = false) String oauthVerifier, @RequestParam(value = "denied", required = false) String denied) { LOGGER.info("received invocation at twitter callback endpoint w/ params: oauth_token=" + oauthToken + ", oauth_verifier=" + oauthVerifier + ", denied=" + denied); TwitterAPI twitterAPI = twitterService.getInstance(); if (!twitterAPI.isConfigured()) { LOGGER.error("Received invocation at Twitter callback endpoint, but service not yet configured"); redirectAttrs.addFlashAttribute("errors", Arrays.asList("api.not.configured.twitter")); } else {/*w ww .j ava 2s. co m*/ if (denied != null) { String errorMessage = "Received error from Twitter server: " + denied; LOGGER.info(errorMessage); redirectAttrs.addFlashAttribute("errorMessage", errorMessage); } else { try { User user = Authenticate.getUser(); TwitterUser twitterUser = twitterService.getAuthenticatedUser(user); Twitter instance = new TwitterFactory().getInstance(); instance.setOAuthConsumer(twitterAPI.getClientId(), twitterAPI.getClientSecret()); RequestToken requestToken = new RequestToken(twitterUser.getOauthToken(), twitterUser.getOauthTokenSecret()); AccessToken oAuthAccessToken = instance.getOAuthAccessToken(requestToken, oauthVerifier); twitterService.parseResponse(twitterUser, oAuthAccessToken); } catch (TwitterException | AccessTokenNotProvidedException e) { e.printStackTrace(); redirectAttrs.addFlashAttribute("errors", Arrays.asList(e.getClass().getSimpleName())); } } } return "redirect:/bennu-social-admin"; }
From source file:org.keycloak.social.twitter.TwitterProvider.java
License:Open Source License
@Override public SocialUser processCallback(SocialProviderConfig config, AuthCallback callback) throws SocialProviderException { if (callback.getQueryParam("denied") != null) { throw new SocialAccessDeniedException(); }/* w w w. j av a 2s . c om*/ try { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(config.getKey(), config.getSecret()); String token = callback.getQueryParam("oauth_token"); String verifier = callback.getQueryParam("oauth_verifier"); RequestToken requestToken = new RequestToken((String) callback.getAttribute("token"), (String) callback.getAttribute("tokenSecret")); twitter.getOAuthAccessToken(requestToken, verifier); twitter4j.User twitterUser = twitter.verifyCredentials(); SocialUser user = new SocialUser(Long.toString(twitterUser.getId()), twitterUser.getScreenName()); user.setName(twitterUser.getName()); return user; } catch (Exception e) { throw new SocialProviderException(e); } }
From source file:uk.ac.cam.cl.dtg.segue.auth.TwitterAuthenticator.java
License:Apache License
@Override public String getAuthorizationUrl(final OAuth1Token token) { return new RequestToken(token.getToken(), token.getTokenSecret()).getAuthenticationURL(); }