Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I checked the devise github page to see what they were up to. That project is moving pretty fast and as it happens they have support for facebook connect amongst other things. Check out the section on OAuth2. They use github as an example but it would be the same thing for facebook and they mention differences. I think this is the way to go, third party gems for devise don't move as fast as devise or rails do. Cheers.</p> <p>Oops here's the link <a href="http://github.com/plataformatec/devise" rel="noreferrer">http://github.com/plataformatec/devise</a></p> <p><strong>Edit</strong></p> <p>Of course I did very little coding here mostly went with the default, so here goes:</p> <p>Create a new app and add these gems to the gemfile.</p> <pre><code>gem 'devise', :git =&gt; 'git://github.com/plataformatec/devise.git' gem 'oauth2', :git =&gt; 'git://github.com/intridea/oauth2.git' </code></pre> <p>Run bundle install, then these commands gets you going with a basic User authentication model.</p> <pre><code>rails generate devise:install rails generate devise User </code></pre> <p>In config/initializers/devise.rb uncomment/modify these. Look at the last paragraph as to where you get app_key and secret from facebook.</p> <pre><code>config.oauth :facebook, 'app_key', 'secret', :site =&gt; 'https://graph.facebook.com', :authorize_path =&gt; '/oauth/authorize', :access_token_path =&gt; '/oauth/access_token' </code></pre> <p>This should be your user model.</p> <pre><code>class User &lt; 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 =&gt; data["name"], :email =&gt; data["email"], :password =&gt; Devise.friendly_token) end end end </code></pre> <p>Devise uses a root :to => "something#here" so I created a home controller with a index action and used that to root the application. But nevermind that. I put that in layout/application.html.erb so that I had basic sign_n sign_out routes.</p> <pre><code>&lt;span&gt; &lt;%- if user_signed_in? %&gt; &lt;%= "Signed in as #{current_user.full_name}. Not you?" %&gt; &lt;%= link_to 'Sign out', destroy_user_session_path %&gt; &lt;%- else %&gt; &lt;%= link_to 'Sign in', new_user_session_path %&gt; &lt;%- end %&gt; &lt;/span&gt; </code></pre> <p>Devise pretty much takes care of everything else for us. What you do need to do though is get your app_key and secret from facebook (used in devise.rb config file). This link should get you going. <a href="http://developers.facebook.com/setup" rel="noreferrer">http://developers.facebook.com/setup</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload