hupili / snsapi

Cross platform middleware for Social Networking Services: Twitter, Facebook, SinaWeibo, Renren, RSS, Email, Sqlite, ... (more coming)
http://snsapi.ie.cuhk.edu.hk
160 stars 53 forks source link

Refresh Token ([OT]--a demo followed) #21

Closed hupili closed 11 years ago

hupili commented 12 years ago

I just checked the data structure returned by QQ and Renren (*.save files). The two platforms have refresh_token in it. It's better to refresh the access_key when it's near timeout. Then we don't have to prompt user's browser every time. I'm not sure whether the SP really implement the function of refresh. Check it out later.

Sina is the big brother... One day timeout; no refresh_token returned....

@uxian

daimajia commented 11 years ago

I commited a simpler weibo-test. https://github.com/xuanqinanhai/snsapi/blob/master/simple-weibo-test.py and I checked save file

[
  {
    "platform": "SinaWeiboStatus", 
    "text_length_limit": 140, 
    "user_id": "", 
    "channel_name": "test_weibo", 
    "auth_info": {
      "save_token_file": "(default)", 
      "callback_url": "https://snsapi.ie.cuhk.edu.hk/aux/auth.php", 
      "cmd_fetch_code": "(default)", 
      "cmd_request_url": "(default)"
    }, 
    "app_secret": "96bcc1e00268d7e415c32212b3e197fb", 
    "open": "yes", 
    "app_key": "3644324674"
  }
]

and also checked a detail timeout document in weibo auth document "How to calculate overdue time?" Chinese :access_token自动延续方案 I think we can add a auth time (when authed?) to json saved file and using auth level query to know how long the token will be useless. save two times ( when authed ? and how long it can be last ) to json file. Judge if open browser when a new behavior(which needs to using token) called.

ps:I added something in talk page,waiting for your reply.

hupili commented 11 years ago

Hi,

For the demo test script:

For the access_token refresh matter:

daimajia commented 11 years ago
hupili commented 11 years ago

Sorry for the confusion of "tests" folder. It is the unit test of snsapi, which is intended to be run by developers. For union tests, one needs to operate in snscli or write the scripts like the above one. As to the Key you hardcode in the script, I will add some details later. All the OSNs we currently touch do not allow other users to authorize test stage Apps, e.g. only the developer can authorize it. In this case, everyone needs to register as a developer first and apply their own key. If you really want to lower the barrier of first trial, you need to supply a key pair of formal application (passing certain audit process.... it's annoying... #11 ).

hupili commented 11 years ago

The reason for not automatically trigger re-authorization is because we have different use cases. If you tap into the auth code of snsbase you will find that we support several methods to accomplish 1st and 2nd stage of authorization. By default, assuming you are using it on your desktop, we prompt the browser and fetch the code by a lightweight HTTP server in the backend. In other situations, you don't have such environment. For example, the demo of clock. It is intended to run on a server (maybe you can only touch it through a terminal). So we use "console_output" and "console_input" to request URL / collect code. If refresh_token is effect, we can refreshing access_token for this platform automatically in the SNSAPI layer. Otherwise, I think it will be better to let the App layer decide how to proceed. e.g. they can call is_expired() to check and trigger re-authorization using auth().

hupili commented 11 years ago

This thread is off-topic. The title is modified for future search.

The demand of support of refresh_token is quite low now: