I'm trying to get an OAuth implementation running on a servlet for Twitter. I'm having trouble with redirecting the user to the Twitter authentication page. When I get the callback, it's returned to a servlet but the session is different since the request comes from Twitter and not my webapp.
I tried using encodeRedirectURL to get the session to persist to the outside site but th开发者_高级运维at doesn't work. Need help!
You have to add the session ID as jsessionid
fragment of callback URL. Twitter has to callback to http://example.com/callbackservlet;jsessionid=1E6FEC0D14D044541DD84D2D013D29ED (note: the jsessionid value is here just an example).
The HttpServletResponse#encodeRedirectURL()
(and encodeURL()
) won't encode the URL when the client already supports cookies. You need to hard-encode it yourself.
String url = "http://example.com/callbackservlet";
String encodedURL = url + ";jsessionid=" + request.getSession().getId();
精彩评论