Can I pass the variable to the callback url after authentication via facebook

I use hybridauth to register users on my php site via facebook.

$hybridauth = new Hybrid_Auth( $config ); $facebook = $hybridauth->authenticate( "Facebook" ); $facebook_user_profile = $facebook->getUserProfile(); 

( $config contains the identifier and secret key for my application)

This all works well, but I would like to redirect the user when he returns to the callback url based on which page they are logged in, so I can return them to this location after logging in.

Is there a way to send custom variables using authentication (like a URL or even a simple identifier) โ€‹โ€‹so that I can read them at the other end of the process and find out where the authentication request was triggered.

Is this possible, or am I barking the wrong tree?

If you know how to do this using a hybrid, then any suggestions that put me on the right track are more welcome.

+4
source share
4 answers

Whenever a login is used on the server side or on the client side, the final sending will occur in the dialog box of the FB Login dialog.

Pay attention to the server-side entry in the FB entry architecture to understand the flow.

The login URL will look like

 https://www.facebook.com/dialog/oauth? client_id=YOUR_APP_ID& redirect_uri=YOUR_REDIRECT_URI& state=SOME_ARBITRARY_BUT_UNIQUE_STRING 

Here you can specify any URL for the redirect_url parameter, and after the login stream, Facebook will try to redirect the specified URL. The URL you specify must be a URL with the same base domain as your applicationโ€™s settings.

Also, if you need to save additional data that could be used after logging in, you can use the state parameter. The value you give for this parameter will be returned without any changes.

I hope that if you find the HybridAuth code, you can find out where you need to transfer this data.

+7
source

I can imagine two simple options:

GET parameters: Embed your custom variables as GET parameters in the callback URL. (do not forget the URL to encode data)

Session: Configure user variables in a user session before starting the authentication method.

+3
source

Make sure you pass redirect_url in $config .

Or you can use php header() in your login() function after setting the session and cookie. For instance:

 header("Location: http://www.example.com/some/where/else"); /* Redirect */ 

Hope this helps you. Thanks.

+1
source

Facebook encourages developers to use session variables. state parameter reserved / intended for CSRF

https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/#token

0
source

All Articles