Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Omniauth在登录时未更新OAuth令牌机密_Ruby On Rails 3_Twitter_Omniauth - Fatal编程技术网

Ruby on rails 3 Omniauth在登录时未更新OAuth令牌机密

Ruby on rails 3 Omniauth在登录时未更新OAuth令牌机密,ruby-on-rails-3,twitter,omniauth,Ruby On Rails 3,Twitter,Omniauth,我使用Omniauth通过Twitter和Facebook对用户进行身份验证,遵循关于该主题的“标准”教程(尽管我使用的是Authlogic,而不是Deave) 我可以使用Twitter登录,但无法处理经过身份验证的请求,因为我的Twitter访问令牌机密在Twitter端已更改,但在应用程序端未更新。我尝试删除身份验证,但出于某种原因,它只是保存了旧的身份验证 身份验证\u controller.rb def create omniauth = request.env['omniauth.

我使用Omniauth通过Twitter和Facebook对用户进行身份验证,遵循关于该主题的“标准”教程(尽管我使用的是Authlogic,而不是Deave)

我可以使用Twitter登录,但无法处理经过身份验证的请求,因为我的Twitter访问令牌机密在Twitter端已更改,但在应用程序端未更新。我尝试删除身份验证,但出于某种原因,它只是保存了旧的身份验证

身份验证\u controller.rb

def create
  omniauth = request.env['omniauth.auth']
  authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])

  if authentication
    # User is already registered with application
    flash[:notice] = 'Signed in successfully.'
    sign_in_and_redirect(authentication.user)
  elsif current_user
    # User is signed in but has not already authenticated with this social network
    current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'], :token => (omniauth['credentials']['token'] rescue nil), :secret => (omniauth['credentials']['secret'] rescue nil))
    current_user.apply_omniauth(omniauth)
    current_user.save

    flash[:notice] = 'Authentication successful.'
    redirect_to root_url
  else
    # User is new to this application
    @user = User.new
    @user.apply_omniauth(omniauth)

    if @user.save
      flash[:notice] = 'User created and signed in successfully.'
      sign_in_and_redirect(@user)
    else
      session[:omniauth] = omniauth.except('extra')
      redirect_to new_user_path
    end
  end
end
user.rb

def apply_omniauth(omniauth)
  self.email = "foo@example.com"
  self.login = omniauth['user_info']['nickname'] if login.blank?
  authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'], :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'])
end

有什么想法吗?Rails 3.0.6和Ruby 1.8.7,Steve,您可以尝试以下操作:

if authentication
 # Make sure we have the latest authentication token for user
 if omniauth['credentials']['token'] && omniauth['credentials']['token'] != authentication.token
   # puts "Found Invalid token"
   authentication.update_attribute(:token, omniauth['credentials']['token'])
 end
 flash[:notice] = "Signed in successfully"
 sign_in_and_redirect(:user, authentication.user)
elsif ...
这基本上应该在已经注册的用户每次尝试登录以及出现令牌不匹配时更新用户的访问令牌