开发者

Servlets encodeRedirectURL

开发者 https://www.devze.com 2023-01-15 04:11 出处:网络
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

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消