devise の github ページをチェックして、彼らが何をしているのかを確認しました。そのプロジェクトはかなり急速に進んでおり、たまたま Facebook コネクトがサポートされています。OAuth2 のセクションを確認してください。彼らは例として github を使用していますが、Facebook でも同じであり、違いについて言及しています。これが進むべき道だと思います.devise用のサードパーティのgemは、deviseやrailsほど速く動きません。乾杯。
おっと、ここにリンクがあります http://github.com/plataformatec/devise
編集
もちろん、ここではほとんどコーディングを行っていませんが、ほとんどはデフォルトで行ったので、次のようになります。
新しいアプリを作成し、これらの gem を gemfile に追加します。
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
gem 'oauth2', :git => 'git://github.com/intridea/oauth2.git'
bundle install を実行すると、これらのコマンドで基本的なユーザー認証モデルを使用できます。
rails generate devise:install
rails generate devise User
config/initializers/devise.rb で、これらのコメントを解除/変更します。Facebook から app_key と secret を取得する場所については、最後の段落を参照してください。
config.oauth :facebook, 'app_key', 'secret',
:site => 'https://graph.facebook.com',
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token'
これはユーザー モデルである必要があります。
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable, :timeoutable and :oauthable
devise :database_authenticatable, :oauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
# Get the user email info from Facebook for sign up
# You'll have to figure this part out from the json you get back
data = ActiveSupport::JSON.decode(access_token)
if user = User.find_by_email(data["email"])
user
else
# Create an user with a stub password.
User.create!(:name => data["name"], :email => data["email"], :password => Devise.friendly_token)
end
end
end
Devise はルート :to => "something#here" を使用するため、インデックス アクションを使用してホーム コントローラーを作成し、それを使用してアプリケーションをルート化しました。しかし、気にしないでください。これを layout/application.html.erb に入れて、基本的な sign_n sign_out ルートを作成しました。
<span>
<%- if user_signed_in? %>
<%= "Signed in as #{current_user.full_name}. Not you?" %>
<%= link_to 'Sign out', destroy_user_session_path %>
<%- else %>
<%= link_to 'Sign in', new_user_session_path %>
<%- end %>
</span>
Devise は私たちに代わって他のすべてを処理してくれます。ただし、必要なことは、app_key とシークレットを Facebook から取得することです (devise.rb 構成ファイルで使用されます)。このリンクはあなたを動かすはずです。http://developers.facebook.com/setup