English 中文(简体)
1. 总括Auth Facebook过期,有误
原标题:OmniAuth Facebook expired token error

我正在利用奥尼·阿乌特来获得我方言中的“Face”。 我使用的是:到Facebook。 我在Heroku的座席上就座。 如果用户日志在较晚的某个时候使用,那么除非用户成立,否则我便会发生变化。

创建用户守则

    class SessionsController < 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 => "Signed in!"  
         end 

用户模式是:

  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

我现在看到这一错误在大约30%的用户中发生。

 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.)

我认为,已经过期的象征性问题最近已经固定在乌阿特:

https://github.com/soopa/omniauth/commit/67bdea962e3b601b8ee70e21aedf5e6ce1c2780”rel=“nofollow”https://github.com/soopa/omniauth/commit/67bdea962e3b601b8ee70e21aedf5e6e2e6e2c2b780

我使用了这一守则,试图重新获得象征性服务。 然而,我仍然有同样的错误。 有些人能够指出我失踪的是什么? 采用某种其他方式,我可以随时更新在上的用户标志。

www.un.org/Depts/DGACM/index_spanish.htm 唯一的解决办法是,每当用户标志时就建立一个新的用户。 (我根本不喜欢这一解决办法):

  def create  
    auth = request.env["omniauth.auth"] 
    user = User.create_with_omniauth(auth)
    session[:user_id] = user.id  
    redirect_to root_url, :notice => "Signed in!"  
  end

感谢!

最佳回答

在你召开本届会议时,你可以简单地向大家通报。

class SessionsController < ApplicationController  
def create  
  auth = request.env["omniauth.auth"]  
  user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]).tap do |u|
           u.update_attributes(:token => auth["credentials"]["token"]) if u
         end || User.create_with_omniauth(auth)
  session[:user_id] = user.id  
  redirect_to root_url, :notice => "Signed in!"  
end 
问题回答

在你回答这一问题之前,我采用了类似的解决办法。

  class SessionsController < ApplicationController  
  def create  
 auth = request.env["omniauth.auth"]  
 user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) ||  User.create_with_omniauth(auth)  

 user.update_attributes(:token => auth["credentials"]["token"])

 session[:user_id] = user.id  
 redirect_to root_url, :notice => "Signed in!"  

  end

在此情况下,我们能否用FBGraph gem的热点法重塑。

auth = FbGraph::Auth.new(CLIENT_ID, CLIENT_SECRET)
auth.exchange_token! access_token # Needs fb_graph 2.3.1+
auth.access_token # => new token

However, This will not extend token s expiry but will replace token with new one. Expiry time will remain same. Checked it with FB, They may not allow to extend FB token expiry more than 60 days. Maximum token validity is 60-days.

http://github.com/nov/fb_graph/wiki/Authentication#wiki-extend-token-expiry”rel=“nofollow”





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签