Note that there are some explanatory texts on larger screens.

plurals
  1. POOmniAuth Facebook expired token error
    text
    copied!<p>I am using OmniAuth to get access to Facebook in my app. I am using the fb_graph gem: <a href="https://github.com/nov/fb_graph" rel="nofollow">https://github.com/nov/fb_graph</a> to post to Facebook. I am running omniauth-0.3.0 on Heroku for this app. The token that I save when the user is created is changed when the user logs in sometime later.</p> <p>Code for creating user</p> <pre><code> class SessionsController &lt; ApplicationController def create auth = request.env["omniauth.auth"] user = User.find_by_provider_and_uid(auth["provider"], auth["uid"])|| User.create_with_omniauth(auth) session[:user_id] = user.id redirect_to root_url, :notice =&gt; "Signed in!" end </code></pre> <p>The User model is:</p> <pre><code> def self.create_with_omniauth(auth) create! do |user| user.provider = auth["provider"] user.uid = auth["uid"] user.name = auth["user_info"]["name"] user.token = auth["credentials"]["token"] end end </code></pre> <p>I am now seeing this error on about 30% users- </p> <pre><code> 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 was created or Facebook has changed the session for security reasons.) </code></pre> <p>I saw that the expired token issue has been recently fixed in OmniAuth: </p> <p><a href="https://github.com/soopa/omniauth/commit/67bdea962e3b601b8ee70e21aedf5e6ce1c2b780" rel="nofollow">https://github.com/soopa/omniauth/commit/67bdea962e3b601b8ee70e21aedf5e6ce1c2b780</a></p> <p>I used this code which tries to refresh the access token. However, I still get the same error. Can someone point to what I am missing? <strong>Is there some other way I could update the token every time the user logs in?</strong></p> <p><strong>The only solution which has worked is to create a new User everytime the User logs in</strong> (I don't like this solution at all):</p> <pre><code> def create auth = request.env["omniauth.auth"] user = User.create_with_omniauth(auth) session[:user_id] = user.id redirect_to root_url, :notice =&gt; "Signed in!" end </code></pre> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload