Struts 2 and the simple Facebook API

I am trying to make a webapp in java that is able to send user status to facebook, and I am having some problems with the authorization process. Basically, I have a struts2 action that redirects the user to the facebook login page, which then redirects me to me with "code". Then I use this code to access another facebook url (to trade it for an access token).

The problem is that I probably just missed something simple, that this second facebook url is not redirected to the action, instead it just returns a page with an access token on it. So my question is: how can I access this token for input into my database, preferably without showing the access token to the end user?

TL; DR; Any idea how I could trigger a request from an action in struts2 to an external url and parse the response without showing it to the user? Thank!

Cheers, Lucas Rezek

+3
source share
2 answers

So basically you would like 3 pieces:

  • interceptor
  • AuthRequest action
  • authResponse action

So the thread:

  • The interceptor will check if the current user has an authentication token, if not, it will redirect the authRequest action
  • The authRequest action will populate your application data - create the url graph.facebook.com/oauth/authorize?client_id=xxx&redirect_uri=yyy, etc. Note that redirect_uri exactly matches the authResponse action. therefore, after the user allows your application, the browser will be redirected to the authResponse action
  • authResponse - , , , , . , - , .
+3

- struts, . socket.outputstream socket.inputStream , Apache HttpComponents HTMLUnit.

- Facebook - , FB facebook, . HTMLUnit, .

0

Source: https://habr.com/ru/post/1793499/


All Articles