I am writing a web application and have just realized that a user can log in via Twitter using spring -social- (core / twitter).
However, Twitter is acting weird. After the initial authentication / authorization, every time I send a user to Twitter for authentication, Twitter offers to allow my expression again. I looked at the connected Twitter profile. My application is there and allowed correctly (in my case, for read access).
I have no case for requesting additional permissions. All my needs of the application are read access (an authorization dialog confirms this).
I use OAuth1Operations
(returned by TwitterConnectionFactory
) to dance OAuth and store the resulting connection in the database. My interface is written using Wicket 1.5.
I can get around this behavior by simply re-authorizing my application again and again when I want to log in via Twitter, but this is a big nuisance. Does anyone know what I'm missing here?
Here is my code:
TwitterConnectionFactory connectionFactory = (TwitterConnectionFactory) connectionFactoryLocator.getConnectionFactory(Twitter.class); String callbackUrl = [...]; if (pageParameters.get("oauth_token").isNull() || pageParameters.get("oauth_verifier").isNull()) { MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("x_auth_access_type", "read"); OAuthToken token = connectionFactory.getOAuthOperations().fetchRequestToken(callbackUrl, params); String url = connectionFactory.getOAuthOperations().buildAuthorizeUrl(token.getValue(), OAuth1Parameters.NONE); getSession().setAttribute("twitter_token", token); setResponsePage(new RedirectPage(url)); } else { String token = pageParameters.get("oauth_token").toString(); String verifier = pageParameters.get("oauth_verifier").toString(); OAuthToken previousToken = (OAuthToken) getSession().getAttribute("twitter_token"); if (previousToken.getValue().equals(token)) { AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(previousToken, verifier); OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(authorizedRequestToken, null); Connection<Twitter> connection = connectionFactory.createConnection(accessToken); } }
r3nj1 source share