Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts 2 and a simple Facebook API

I am trying to make a webapp in java that is capable of posting to a users facebook status, 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 back to me with a "code". I then use this code to access another facebook URL (to trade it for an access token).

The problem is, and I'm likely just missing something simple, that this second facebook url doesn't redirect to an action, it instead just returns a page with the access token on it. So, my question is, how would I access that token to put into my database, preferably without showing the access token to the end user?

TLDR; Any idea how I could call a request from an action in struts2 to an external url and parse the response without showing it to the user? Thanks!

Cheers, Lukas Rezek

like image 902
lukas Avatar asked Sep 15 '26 01:09

lukas


1 Answers

So basically you would want 3 pieces:

  1. Interceptor
  2. authRequest action
  3. authResponse action

So the flow is:

  1. Interceptor would check if current user has auth token, if not - it will redirect to authRequest action
  2. authRequest action will fill up your app details - create url graph.facebook.com/oauth/authorize?client_id=xxx&redirect_uri=yyy etc Please note that redirect_uri is exactly is authResponse action. so after user authorizes your app - browser willo redirect to authResponse action
  3. authResponse action is the plave where you retreive the token, save it to DB and probably set it to session. after you done with that - you are done with login and you can redirect to your application home action
like image 116
tevch Avatar answered Sep 16 '26 14:09

tevch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!