为什么我收到“这个授权码已被使用”前2位用户之后? [英] Why am I receiving "This authorization code has been used" after the first 2 users?
问题描述
我正在使用Omniauth-Facebook来创建和验证用户。它适用于两个第一个用户,但第三个用户失败。我还可以认证这是CREATE进程失败。这似乎是一个常见的问题,没有解决方案。
I'm using Omniauth-Facebook to create and authenticate User. It works for the two first users, but fails for the third one. I still can authenticate; it's the CREATE process which fails. This appears to be a common issue without a solution.
error.log:
error.log:
facebook) Callback phase initiated.
(facebook) Authentication failure! invalid_credentials: OAuth2::Error, :
{"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}}
onmiauth.rb:
onmiauth.rb:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :facebook, 'xxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
:scope => 'email,user_birthday,user_hometown,user_location', :display => 'popup'
end
SessionsController:
SessionsController:
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
player = Player.find_by_provider_and_uid(auth["provider"], auth["uid"]) || Player.create_with_omniauth(auth)
session[:player_id] = player.id
redirect_to bienvenue_index_path, :notice => "Signed in!"
end
def destroy
session[:player_id] = nil
redirect_to root_url, :notice => "Signed out!"
end
end
我的播放器型号:
class Player < ActiveRecord::Base
attr_accessible :email, :gender, :habitation, :image, :nom, :nom_complet, :prenom, :provider, :token, :uid, :taille, :poids, :pied, :poste_prefere, :vehicule
has_many :matches
has_many :activities
validates_presence_of :prenom
validates_presence_of :nom
def self.create_with_omniauth(auth)
large = "http://graph.facebook.com/#{auth["uid"]}/picture?type=large"
create! do |player|
player.provider = auth["provider"]
player.uid = auth["uid"]
player.nom_complet = auth["info"]["name"]
player.nom = auth["info"]["last_name"]
player.prenom = auth["info"]["first_name"]
player.image = auth["info"]["image"]
player.image_large = large
player.email = auth["info"]["email"]
player.gender = auth["extra"]["raw_info"]["gender"]
player.habitation = auth["extra"]["raw_info"]["location"]["name"]
player.token = auth["credentials"]["token"]
end
end
end
推荐答案
对于绊倒同样错误的其他人来说,我的另一个问题是由另一个问题引起。
For other people who stumble over this same error mine was caused by another issue.
通过 skip_before_filter:
Users :: OmniauthCallbacksController
为什么我认为这是有效的:
最初我跟踪了这个 bug 在omniauth_facebook gem中。
Initially I followed the the trail to this bug in the omniauth_facebook gem.
这突出显示了错误消息与两个FB回调请求快速连续发送的事实有关。不幸的是,我没有定义两次的全面细节,所以最初没有办法解决这个问题。
This highlighted the fact that the error message relates to the fact that two FB callback requests are being sent in quick succession. Unfortunately, I didn't have the omniauth details defined twice so initially couldn't work out where that was coming from.
然后我意识到在我的 ApplicationController
我有 before_filter:authenticate
。我认为发生了什么事情是Facebook的回拨请求正在触发此认证屏障,然后立即请求新的身份验证。
Then I realised that in my ApplicationController
I have before_filter :authenticate
. I think what was happening was that the Facebook callback request was hitting this authentication barrier and then immediately request a new authentication.
告诉Devise跳过此动作解决了我的问题。
Telling Devise to skip this action resolved the issue for me.
这篇关于为什么我收到“这个授权码已被使用”前2位用户之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!