List of usage examples for twitter4j.conf ConfigurationBuilder setIncludeEmailEnabled
public ConfigurationBuilder setIncludeEmailEnabled(boolean enabled)
From source file:org.wso2.carbon.identity.authenticator.twitter.TwitterAuthenticator.java
License:Open Source License
/** * Initiate the authentication request/* w w w.j a v a 2s . c o m*/ */ @Override protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws AuthenticationFailedException { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); Map<String, String> authenticatorProperties = context.getAuthenticatorProperties(); String apiKey = authenticatorProperties.get(TwitterAuthenticatorConstants.TWITTER_API_KEY); String apiSecret = authenticatorProperties.get(TwitterAuthenticatorConstants.TWITTER_API_SECRET); configurationBuilder.setIncludeEmailEnabled(true); Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance(); twitter.setOAuthConsumer(apiKey, apiSecret); try { String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier()); String callbackURL = getCallbackUrl(authenticatorProperties); RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString()); String subStr = queryParams .substring(queryParams.indexOf(TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY + "=")); String sessionDK = subStr .substring(subStr.indexOf(TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY + "="), subStr.indexOf("&")) .replace((TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY + "="), ""); request.getSession().setAttribute(TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY, sessionDK); request.getSession().setAttribute(TwitterAuthenticatorConstants.TWITTER_REQUEST_TOKEN, requestToken); request.getSession().setAttribute(TwitterAuthenticatorConstants.AUTHENTICATOR_NAME.toLowerCase(), twitter); response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { log.error("Exception while sending to the Twitter login page.", e); throw new AuthenticationFailedException(e.getMessage(), e); } catch (IOException e) { log.error("Exception while sending to the Twitter login page.", e); throw new AuthenticationFailedException(e.getMessage(), e); } }