Do Facebook Oauth 2.0 Access Tokens Expire?

后端 未结 13 1161
Happy的楠姐
Happy的楠姐 2020-11-27 09:32

I am playing around with the Oauth 2.0 authorization in Facebook and was wondering if the access tokens Facebook passes out ever expire. If so, is there a way to request a l

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 10:14

    You can always refresh the user's access token every time the user logs into your site through facebook. The offline access can't guarantee you get a life-long time access token, the access token changes whenever the user revoke you application access or the user changes his/her password.

    Quoted from facebook http://developers.facebook.com/docs/authentication/

    Note: If the application has not requested offline_access permission, the access token is time-bounded. Time-bounded access token also get invalidated when the user logs out of Facebook. If the application has obtained offline_access permission from the user, the access token does not have an expiry. However it gets invalidated whenever the user changes his/her password.

    Assume you store the user's facebook uid and access token in a users table in your database,every time the user clicks on the "Login with facebook" button, you check the login statususing facebook Javascript API, and then examine the connection status from the response,if the user has connected to your site, you can then update the access token in the table.

提交回复
热议问题