This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.feature 'Facebook login management', type: :feature do | |
before(:each) do | |
OmniAuth.config.test_mode = true | |
mock_auth_hash | |
end | |
scenario 'Should login over facebokok do | |
visit '/users/sign_up' | |
click_on 'Facebook OAuth' | |
#..... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module OmniauthMacros | |
def mock_auth_hash | |
OmniAuth.config.mock_auth[:default] = OmniAuth::AuthHash.new( | |
'provider' => 'facebook', | |
'uid' => '123545', | |
'info' => { | |
'name' => 'mockuser', | |
'image' => 'mock_user_thumbnail_url', | |
'first_name' => 'john', | |
'last_name' => 'doe', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/oauth.rb | |
on_failure do |env| | |
#we need to setup env | |
if env['omniauth.params'].present | |
env["devise.mapping"] = Devise.mappings[:user] | |
end | |
Devise::OmniauthCallbacksController.action(:failure).call(env) | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%-# app/views/devise/sessions/new.html.erb -%> | |
<%-# put these three lines -%> | |
<%= link_to('/users/auth/facebook', {:class => "btn btn-primary"}) do %> | |
Facebook OAuth | |
<%- end %> | |
<br/> | |
# before this line | |
<%= render "devise/shared/links" %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#execute in terminal | |
rails generate devise:views |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
devise_for :users | |
devise_scope :user do | |
get "/users/auth/facebook/callback" => "users/omniauth_callbacks#facebook" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/oauth.rb | |
Rails.application.config.middleware.use OmniAuth::Builder do | |
provider :facebook, | |
ENV['FACEBOOK_APP_ID'], | |
ENV['FACEBOOK_SECRET_ID'], | |
scope: 'email', | |
info_fields: 'email', | |
auth_type: 'rerequest' | |
configure do |config| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/user.rb | |
# devise :omniauthable, omniauth_providers: [:facebook] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/initializers/devise.rb | |
#config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET_ID'], | |
# scope: 'email', | |
# info_fields: 'email' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# execute from terminal | |
rails generate migration add_oauth_fields_to_users provider:string uid:string | |
rake db:migrate |
NewerOlder