PHP Classes

How to use "State" to post/get variables? Thanks a lot.

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  How to use "State" to post/get...  >  (Un) Subscribe thread alerts  
Subject:How to use "State" to post/get...
Summary:Questions in using the "state" related parameters.
Author:Tiger Chuang
Date:2017-12-05 16:36:34

  1. How to use "State" to post/get...   Reply   Report abuse  
Tiger Chuang - 2017-12-05 16:36:34
Hi, Manuel, thanks for your OAuth-api (php) library. It's very easy to integrate it to handle the authorization process with only a few lines of code. When I study the document, it was found that you also defined the "append_state_to_redirect_uri" and "stored_state" in the class. I wonder that how could those two variables be used to pass the UserID during the authorization process?

We want to use them to save the token in the database with the specific user_ID. The flow is as follows:
1. A user inputs their data to register on the mobile app.
2. He/she clicks the "Authorize" button to send the user id to the "http://PublicWebsite/../login_in_with_fitbit2.php?uid=x".
3. It opens the Authorization page ( with the scopes defined in the codes.
4. After clicking the confirm button, it redirected the user back to login_with_fitbit2.php. At this time, we wanted the webpage to be able to remember the user_ID(?uid=x) passed in the second step.

After reading the document, I tried the "append_state_to_redirect_uri" and "stored_state" with following codes:
$client->state = "uid=" . $uid;
$client->append_state_to_redirect_uri = "?uid=" . $uid;

Was the syntax correct? Unfortunately, I couldn't see the UserID in the URI or get it returned in the login_with_fitbit2.php. Do I need to encode/decode the variables (such as the steps explained in

Could you tell me the correct way to use them or show me some examples?

Thank you very much.

Best wishes, Tiger

  2. Re: How to use "State" to post/get...   Reply   Report abuse  
Manuel Lemos - 2017-12-06 05:43:51 - In reply to message 1 from Tiger Chuang
Sorry I am a bit busy. I believe the answer is in the documentation HTML file already. Can you please take a look a let me know if you still have questions?

  3. Re: How to use "State" to post/get...   Reply   Report abuse  
Olivier Zuccaro - 2018-03-14 09:38:41 - In reply to message 2 from Manuel Lemos
Since I had the same issue with Facebook soon enforcing "strict" authorization (or being mandatory if you want to access instagram datas)

You can override state using the session variable :
$_SESSION['OAUTH_STATE'] = "{mystate=myvalue}";

It is working with a Facebook Auth, I did not try it with anything else.