Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:09:21+00:00 2026-05-27T02:09:21+00:00

does anybody have experience with OmniAuth & Facbeook? I just moved from using a

  • 0

does anybody have experience with OmniAuth & Facbeook? I just moved from using a hardcoded app id & secret key in my application, to the ENV['FACEBOOK_APP_ID'] method. I know that these values are correct, since when I try to log in to my app I get the permissions dialog for the correct app, but then when Facebook redirects back to my app in development mode, I get the error “Authentication error: Invalid credentials”.

In production, however, everything works fine against the production version of the Facebook app settings.

# initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'], :scope => 'email,offline_access,user_work_history'
end

#sessions_controller.rb
class SessionsController < ApplicationController
  def new
    redirect_to '/auth/facebook'
  end

  def callback
    auth = request.env["omniauth.auth"]
    logger.info auth.inspect
    user = User.where(:provider => auth['provider'], :uid => auth['uid']).first || User.create_with_omniauth(auth)
    session[:user_id] = user.id
    session[:token] = auth['credientials']['token']
    redirect_to root_url, :notice => "Signed in!"
  end

  def destroy
    session[:user_id] = nil
    # current_user = nil
    # request.env['omniauth.auth'] = nil
    redirect_to root_url, :notice => 'Signed out!'
  end

  def failure
    logger.info request.inspect
    redirect_to root_url, :alert => "Authentication error: #{params[:message].humanize}"
  end

  def auth; request.env['omniauth.auth'] end
end

#user.rb
  # Authentication Stuff
class User
  include Mongoid::Document
  include Mongoid::Timestamps
  # ...
  def self.create_with_omniauth(auth)
    begin
      create! do |user|
        user.provider = auth['provider']
        user.uid = auth['uid']
        if auth['info']
          user.name = auth['info']['name'] if auth['info']['name'] # Twitter, Google, Yahoo, GitHub
          user.email = auth['info']['email'] if auth['info']['email'] # Google, Yahoo, GitHub
        end
        if auth['extra']['raw_info']
          user.name = auth['extra']['raw_info']['name'] if auth['extra']['raw_info']['name'] # Facebook
          user.email = auth['extra']['raw_info']['email'] if auth['extra']['raw_info']['email'] # Facebook
          user.employer = auth['extra']['raw_info']['work'][0]['employer'] if auth['extra']['raw_info']['work'] # Facebook
        end
      end
      rescue Exception
      raise Exception, "cannot create user record"
    end
  end
end

Then this happens:

Started GET "/auth/facebook" for 127.0.0.1 at 2011-11-26 11:53:38 +0200

Started GET "/auth/facebook/callback?code=AQBapjqIJixqmSxjj-i61WJtJN-ncCBUM_mPyhunqY4esQsaX7wiU794wMSOWT6oRJ0TMl-N5eqNh2MHuap0Oey4i6ef0F8281zQ6V1Vhct3g" for 127.0.0.1 at 2011-11-26 11:53:40 +0200

Started GET "/auth/failure?message=invalid_credentials" for 127.0.0.1 at 2011-11-26 11:53:42 +0200
  Processing by SessionsController#failure as HTML
  Parameters: {"message"=>"invalid_credentials"}
Redirected to http://localapp.dev/
Completed 302 Found in 1ms

Have any idea what I’m missing? I should stress that the only change that I made before this bug was that instead of having provider :facebook, "XXXXXX", "XXXXXXXXXXXXXXX" in my ombiauth.rb initializer, I made it get those values from ENV

-Avishai

# Gemfile
source 'http://rubygems.org'

gem 'rails', '3.0.9'
gem "airbrake"
gem "bson_ext"
gem "mongoid", ">= 2.0.2"
gem "omniauth", "~> 1.0"
gem "omniauth-facebook"
gem "carrierwave", "0.5.4"
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem "geocoder"
gem 'will_paginate'
gem "rmagick"
gem "jquery-rails"
gem "mongoid-history"
gem "mongoid-rating"    
gem "flash_cookie_session"
group :development, :test do
    gem "ya2yaml"
    gem "chronic"
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:09:22+00:00Added an answer on May 27, 2026 at 2:09 am

    Are you actually defining ENV[…] in your local app? That’s typically what you do when deploying to heroku, but if you forget to set the variables locally as well they won’t be there when you run your dev version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does anybody have any experience writing up a offline data storage & access app
Does anybody have any experience with the Raphael.js SVG library? I'm using Raphael.js to
Does anybody have experience with JSR 330 vs Guice? From what I gather Guice
Does anybody have experience programming for both the Intel Math Kernel Library and the
Does anybody have any experience with different fonts for OCR? I am generating an
Does anybody have any experience/ knowledge in installing the aspImage.dll on a 64-bit Windows
Does anybody have any experience with TFS no longer letting somebody queue a new
does anybody know if it's possible (or have experience doing so) to simply bundle
Does anybody have any idea how to print an excel file programatically using C#
Does anybody have experience with converting mp4 files to .wav or mp3 files? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.