0

At some point in this jsf web application, the current user is prompted to identify with Twitter via OAuth.

After the user identified on Twitter the OAUth callback url redirects to my app:

http://www.myJsfApp.com/successAuth.xhtml

But of course without a session id this successAuth.xhtml is not connected to the user session. The page is just the "raw" xhtml file (with all its tags) and no html.

How can I make this callback url to link back to the current session?

seinecle
  • 10,118
  • 14
  • 61
  • 120
  • for start : don't you want to redirect your user to *http://www.myJsfApp.com/successAuth.jsf* (*jsf* suffix) – Daniel Dec 12 '12 at 10:55
  • uhh dunno. The address bar of my app shows xhtml extensions. For example: http://localhost:8080/myApp/faces/index.xhtml;jsessionid=4566F5BB481F9CFB0D2EA588061F2BF7 – seinecle Dec 12 '12 at 11:01
  • ok, so your `FacesServlet` mapped to `faces/` so add the `faces/` prefix to your page *myJsfApp.com/faces/successAuth.xhtml* , Also you might consider creating a `Filter` map it to `successAuth.jsf` and continue from there... (check this as well http://balusc.blogspot.co.il/2007/03/user-session-filter.html) – Daniel Dec 12 '12 at 11:15

1 Answers1

2

But of course without a session id this successAuth.xhtml is not connected to the user session.

If your servletcontainer supports URL rewriting (by default, they all do), then you can just pass the session ID as URL path fragment.

HttpSession session = (HttpSession) externalContext.getSession();
String callbackURL = "http://www.myJsfApp.com/successAuth.xhtml;jsessionid=" + session.getId();
// ...

See also:


The page is just the "raw" xhtml file (with all its tags) and no html.

That will happen when the FacesServlet isn't been invoked. The request URL must match the URL pattern of the FacesServlet in order to invoke it. So, if you have configured it to listen on for example /faces/* URLs, then you should obviously change the URL to faces/successAuth.xhtml.

HttpSession session = (HttpSession) externalContext.getSession();
String callbackURL = "http://www.myJsfApp.com/faces/successAuth.xhtml;jsessionid=" + session.getId();
// ...

Alternatively, you can also just map the FacesServlet on *.xhtml, this way you never need to fiddle with virtual URLs.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555