我正在使用 Omniauth-Facebook 来创建和验证用户。它适用于前两个用户,但不适用于第三个用户。我仍然可以进行身份验证;这是失败的 CREATE 过程。这似乎是一个没有解决方案的常见问题。
错误日志:
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:
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
会话控制器:
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