<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ari Karim on Medium]]></title>
        <description><![CDATA[Stories by Ari Karim on Medium]]></description>
        <link>https://medium.com/@arikarim146?source=rss-ba571138ea0f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5Me7nNzq9S5EQ-dOQNWvhw.jpeg</url>
            <title>Stories by Ari Karim on Medium</title>
            <link>https://medium.com/@arikarim146?source=rss-ba571138ea0f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:42:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arikarim146/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Facebook Omniauth with Devise, Ruby on Rails]]></title>
            <link>https://arikarim146.medium.com/facebook-omniauth-with-devise-ruby-on-rails-29dcf83cbf19?source=rss-ba571138ea0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/29dcf83cbf19</guid>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[facebook-login]]></category>
            <category><![CDATA[omniauth]]></category>
            <dc:creator><![CDATA[Ari Karim]]></dc:creator>
            <pubDate>Sun, 04 Apr 2021 14:09:11 GMT</pubDate>
            <atom:updated>2021-04-04T15:57:17.206Z</atom:updated>
            <content:encoded><![CDATA[<h3>Login with Facebook in Rails 6 and Devise.</h3><p>I can not imagine how it can be stressful when trying to implement third party configuration like Facebook with your application that use devise especially when you get crazy errors.</p><p>here i will show you step by step how to login into your application with Facebook using ‘omniauth-facebook’ gem.</p><p>First of all you need a Facebook developer account, you can register by visiting:</p><ul><li><a href="https://developers.facebook.com/">https://developers.facebook.com/</a></li><li>Click on my apps in the navbar</li><li>Click on create new app</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*EbShSP8LHR9rffM9G3nnfQ.png" /></figure><ul><li>Click on More options</li><li>then click on something else</li><li>then add your display app name</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*d9o7b72amokXril3xQnFLQ.png" /></figure><ul><li>Complete the security check and this should redirect you to the app(please make sure to turn off add blockers otherwise the security check will not popup).</li><li>Click on setting then choose basics</li><li>in the app domains put(localhost).</li><li>then scroll down to Add platform then choose (‘website’)</li><li>then type [https://localhost]</li><li>click on Save changes and save your (app_id and app_secret) for later.</li></ul><blockquote>in your Gemfile put:</blockquote><pre>gem &#39;omniauth-facebook&#39;<br>gem &#39;omniauth&#39;<br>gem &#39;omniauth-rails_csrf_protection&#39;</pre><blockquote>and also change your Devise gem to:</blockquote><pre>gem &#39;devise&#39;, github: &#39;heartcombo/devise&#39;, branch: &#39;ca-omniauth-2&#39;</pre><blockquote>Then we need to add provider and uid strings to the users table so we run:</blockquote><pre>rails g migration AddOmniauthToUsers provider:string uid:string</pre><p>then run ‘rake db:migrate’.</p><blockquote>Then we need to put our app_id and secret inside rails credentials file so to open it we run:</blockquote><pre>`EDITOR=&quot;code --wait&quot; bin/rails credentials:edit`</pre><p>note; if you are not using Vscode so change ‘code’ in the above command with your text editor.</p><blockquote>Then add:</blockquote><pre>facebook:<br>  APP_ID: &lt;facebook_app_id&gt;<br>  APP_SECRET: &lt;facebook_app_secret&gt;</pre><p>and replace them with your APP_ID and APP_SECRET.</p><blockquote>Then inside config/initializers/devise.rb put:</blockquote><pre>config.omniauth :facebook, Rails.application.credentials.facebook[:APP_ID], Rails.application.credentials.facebook[:APP_SECRET], token_params: { parse: :json }</pre><blockquote>Inside your user Model add :</blockquote><pre>devise :omniauthable, omniauth_providers: %i[facebook]</pre><p>and</p><pre>def self.from_omniauth(auth)<br>  name_split = auth.info.name.split(&quot; &quot;)<br>  user = User.where(email: auth.info.email).first<br>  user ||= User.create!(provider: auth.provider, uid: auth.uid, last_name: name_split[0], first_name: name_split[1], email: auth.info.email, password: Devise.friendly_token[0, 20])<br>    user<br>end</pre><blockquote>Then we create a users folder inside app/controllers and inside it create a file called “omniauth_callbacks_controller.rb” and put:</blockquote><pre>class Users::OmniauthCallbacksController &lt;    Devise::OmniauthCallbacksController<br>  def facebook<br>    <a href="http://twitter.com/user">@user</a> = User.from_omniauth(request.env[&quot;omniauth.auth&quot;])</pre><pre>if <a href="http://twitter.com/user">@user</a>.persisted?<br>      sign_in_and_redirect <a href="http://twitter.com/user">@user</a>, event: :authentication #this will throw if <a href="http://twitter.com/user">@user</a> is not activated<br>      set_flash_message(:notice, :success, kind: &quot;Facebook&quot;) if is_navigational_format?<br>    else<br>      session[&quot;devise.facebook_data&quot;] = request.env[&quot;omniauth.auth&quot;].except(:extra) # Removing extra as it can overflow some session stores<br>      redirect_to new_user_registration_url<br>    end<br>  end</pre><pre>def failure<br>    redirect_to root_path<br>  end<br>end</pre><blockquote>Last but not least inside config/routes.rb change “devise_for :users” to:</blockquote><pre>devise_for :users, controllers: { omniauth_callbacks: &#39;users/omniauth_callbacks&#39; }</pre><blockquote>Finally inside the views put this:</blockquote><pre>&lt;%= link_to &quot;Register with Facebook&quot;, user_facebook_omniauth_authorize_path, method: :post %&gt;</pre><p>Note: when you put omniauthable inside the user model it will directly create a link for it and you can see it inside app/views/devise/shared/links, but this link is a get method and it will not work.</p><p>if you want to use it just add this line below at the end of the link:</p><pre>method: :post</pre><p>in some cases due to security protocol of Facebook you should create an “.env” file in the root of your project and add:</p><pre>HTTPS = true</pre><p>and that is all you need to do in order to allow login using Facebook in your application.</p><p>Happy Coding:))</p><h4>Ari Karim</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29dcf83cbf19" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>