Programing

Facebook Oauth 2.0 액세스 토큰이 만료됩니까?

lottogame 2020. 7. 13. 08:12
반응형

Facebook Oauth 2.0 액세스 토큰이 만료됩니까?


Facebook에서 Oauth 2.0 인증을 사용하고 있으며 Facebook에서 전달하는 액세스 토큰이 만료되는지 궁금합니다. 그렇다면 수명이 긴 액세스 토큰을 요청하는 방법이 있습니까?


조금 파고 들자, 나는 이것을 발견했다. 답이 될 것 같습니다.

업데이트 됨 (2018 년 4 월 11 일)

  • 토큰은 약 60 일 후에 만료됩니다.
  • 앱을 사용하는 사람이 Facebook 서버에 요청하면 토큰은 하루에 한 번, 최대 90 일 동안 새로 고쳐집니다.
  • 앱을 사용하는 사람의 동의하에 90 일마다 모든 액세스 토큰을 갱신해야합니다.

페이스 북 변경 발표 (2018 년 10 월 4 일)

Facebook에서 토큰 만료 페이지를 업데이트했습니다 (2018 년 10 월 4 일)

offline_access : 애플리케이션이 언제든지 사용자를 대신하여 승인 된 요청을 수행 할 수 있도록합니다. 기본적으로 대부분의 액세스 토큰은 응용 프로그램이 활발하게 응용 프로그램을 사용하고있을 때 응용 프로그램이 사용자 대신 요청을 할 수 있도록 짧은 시간 후에 만료됩니다. 이 권한으로 OAuth 엔드 포인트가 반환 한 액세스 토큰을 오래 사용할 수 있습니다.

요청 된 권한 값입니다.

http://developers.facebook.com/docs/authentication/permissions

최신 정보

offline_access 권한이 얼마 전에 제거되었습니다.

https://developers.facebook.com/docs/roadmap/completed-changes/offline-access-removal/


이 방법이 도움이 될 수 있습니다.

https://graph.facebook.com/oauth/authorize?
    client_id=127605460617602&
scope=offline_access,read_stream,user_photos,user_videos,publish_stream&
    redirect_uri=http://www.example.com/

평생 액세스 토큰을 얻으려면 사용해야합니다 scope=offline_access

의 의미 scope=offline_access는 :-

애플리케이션이 언제든지 사용자를 대신하여 승인 된 요청을 수행 할 수 있도록합니다. 기본적으로 대부분의 액세스 토큰은 응용 프로그램이 활발하게 응용 프로그램을 사용하고있을 때 응용 프로그램이 사용자 대신 요청을 할 수 있도록 짧은 시간 후에 만료됩니다. 이 권한으로 OAuth 엔드 포인트가 반환 한 액세스 토큰을 오래 사용할 수 있습니다.

그러나 페이스 북의 향후 업그레이드에 따르면 offline_acees 기능은 2012 년 10 월 3 일부터 영구적으로 더 이상 사용되지 않을 것입니다. 사용자에게는 60 일의 장기 액세스 토큰이 제공되며 액세스 토큰이 만료되기 전에 Facebook에서 알리거나 사용자 정의 할 수 있습니다 Facebook Api에서 만료 값을 가져 오는 알림 기능


Facebook은 만료시 "업그레이드"를 요청할 수있는 토큰을 위해 offline_access 권한을 더 이상 사용하지 않습니다. 방금 지금이 문제를 처리하고 있으므로 할 말이 많지 않지만이 문서가 도움이 될 수 있습니다.

https://developers.facebook.com/docs/offline-access-deprecation/


나는 OP와 같은 질문으로 여기에 왔지만 offline_access의 사용을 제안하는 대답은 나를 위해 붉은 깃발을 제기하고 있습니다.

보안 측면에서 사용자의 Facebook 계정에 오프라인으로 액세스하는 것은 단일 로그온을 위해 Facebook을 사용하는 것보다 질적으로 다르며 훨씬 강력하므로 실제로 사용하지 않는 한 가볍게 사용해서는 안됩니다. 사용자가이 권한을 부여하면 "응용 프로그램"은 언제 어디서나 사용자 계정을 검사 할 수 있습니다. "응용 프로그램"은 실제로 자격 증명이있는 도구이므로 따옴표로 묶습니다. 웹 서버와 관련이없는 모든 도구 모음을 스크립팅하여 사용자가 공유하기로 동의 한 모든 정보에 액세스 할 수 있습니다. 신임장.

이 기능을 사용하여 짧은 토큰 수명을 해결하지는 않겠습니다. 의도 된 목적이 아닙니다. 실제로 토큰 수명 자체는 보안 기능입니다. 나는 여전히 이러한 토큰의 올바른 사용법에 대한 세부 정보를 찾고 있습니다 (지속 할 수 있습니까? 어떻게 보호해야합니까? Facebook은 OAuth 2.0 "새로 고침 토큰"을 기본 토큰에 포함합니까? / 또는 어떻게 새로 고치나요?), offline_access가 올바른 방법이 아니라고 확신합니다.


예, 만료됩니다. 'access_token'과 함께 전달되는 'expires'값이 있으며, 내가 말할 수있는 것은 약 2 시간입니다. 검색 중이지만 더 긴 만료 시간을 요청할 수있는 방법이 없습니다.


since i had the same problem - see the excellent post on this topic from ben biddington, who clarified all this issues with the wrong token and the right type to send for the requests.

http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/


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.


Hit this to exchange a short living access token for a long living/non expiring(pages) one:

https://graph.facebook.com/oauth/access_token?             
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN 

log into facebook account and edit your application settings(account -> application setting ->additional permission of the application which use your account). uncheck the permission (Access my data when I'm not using the application(offline_access)). Then face will book issue a new token when you log in to the application.


Basic the facebook token expires about in a hour. But you can using 'exchange' token to get a long-lived token https://developers.facebook.com/docs/facebook-login/access-tokens

GET /oauth/access_token?  
    grant_type=fb_exchange_token&           
    client_id={app-id}&
    client_secret={app-secret}&
    fb_exchange_token={short-lived-token} 

check the following things when you interact with facebook graph api.

1) Application connect URL should be the base of your "redirect_uri" connect URL:- www.x-minds.org/fb/connect/ redirect_uri - www.x-minds.org/fb/connect/redirect 2) Your "redirect_uri" should be same in the both case (when you request for a verification code and request for an access_token) redirect_uri - www.x-minds.org/fb/connect/redirect 3) you should encode the the argument when you request for an access_token 4) shouldn't pass the argument (type=client_cred) when you request for an access_token. the authorization server will issue a token without session part. we can't use this token with "me" alias in graph api. This token will have length of (40) but a token with session part will have a length of(81). An access token without session part will work with some cases

eg: -https://graph.facebook.com/?access_token=116122545078207|EyWJJYqrdgQgV1bfueck320z7MM. But Graph API with "me" alias will work with only token with session part.


I don't know when exactly the tokens expire, but they do, otherwise there wouldn't be an option to give offline permissions.

Anyway, sometimes requiring the user to give offline permissions is an overkill. Depending on your needs, maybe it's enough that the token remains valid as long as the website is opened in the user's browser. For this there may be a simpler solution - relogging the user in periodically using an iframe: facebook auto re-login from cookie php

Worked for me...

참고URL : https://stackoverflow.com/questions/2687770/do-facebook-oauth-2-0-access-tokens-expire

반응형