Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

automatically refresh expired tokens

  • Loading branch information...
commit 67bdea962e3b601b8ee70e21aedf5e6ce1c2b780 1 parent bc4ad50
authored January 10, 2011
11  oa-oauth/lib/omniauth/strategies/oauth2.rb
@@ -61,6 +61,17 @@ def callback_phase
61 61
         
62 62
         verifier = request.params['code']
63 63
         @access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
  64
+        
  65
+        if @access_token.expires? && @access_token.expires_in <= 0
  66
+          client.request(:post, client.access_token_url, { 
  67
+              'client_id' => client_id,
  68
+              'grant_type' => 'refresh_token', 
  69
+              'client_secret' => client_secret,
  70
+              'refresh_token' => @access_token.refresh_token 
  71
+            })
  72
+          @access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
  73
+        end
  74
+        
64 75
         super
65 76
       rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
66 77
         fail!(:invalid_credentials, e)

3 notes on commit 67bdea9

Dan Hixon

Did you ever send a pull request for this?

Adam Michela
Owner

Yep it was merged in quite awhile ago.

sbhalerao

I still get the error: FbGraph::InvalidToken (OAuthException :: Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session.

The user has not changed the password. I don't know why the access token is still not refreshed. Am I missing something here?

Thanks for the fix and the help,
Shantanu

Please sign in to comment.
Something went wrong with that request. Please try again.