ユーザーの作成と認証に Omniauth-Facebook を使用しています。最初の 2 人のユーザーには機能しますが、3 番目のユーザーには失敗します。まだ認証できます。失敗するのは 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