grabury
grabury

Reputation: 5559

NoAuthorizationCodeError for facebook omniauth

I've tried everything and cant solve this NoAuthorizationCodeError error from the facebook omniauth gem.

I've basically copied and pasted railscasts ep360. I've tried to remove the coffee script, I've changed to gem vs 1.4.0, I've tried different versions of rails.

Any help would be appreciated.

at=info method=GET path=/auth/facebook/callback host=enigmatic-sands-2189.herokuapp.com fwd="105.228.66.17" dyno=web.1 connect=2ms service=27ms status=500 bytes=643
2013-10-14T19:20:29.091206+00:00 heroku[router]: at=info method=GET path=/auth/facebook/callback host=enigmatic-sands-2189.herokuapp.com fwd="105.228.66.17" dyno=web.1 connect=14ms service=27ms status=500 bytes=643
2013-10-14T19:20:29.071596+00:00 app[web.1]: Started GET "/auth/facebook/callback" for 105.228.66.17 at 2013-10-14 19:20:29 +0000
2013-10-14T19:20:29.075493+00:00 app[web.1]: (facebook) Callback phase initiated.
2013-10-14T19:20:29.084256+00:00 app[web.1]: 
2013-10-14T19:20:29.084256+00:00 app[web.1]: OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (must pass either a `code` parameter or a signed request (via `signed_request` parameter or a `fbsr_XXX` cookie)):

Sessions controller

class SessionsController < ApplicationController
  def create
    user = User.from_omniauth(env["omniauth.auth"])
    session[:user_id] = user.id
    redirect_to root_url
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url
  end
end

Routes

    root to: 'static_pages#home'

  match 'auth/:provider/callback', to: 'sessions#create'
  match 'auth/failure', to: redirect('/')
  match 'signout', to: 'sessions#destroy', as: 'signout'

Gem file

ruby '1.9.3'

gem 'rails', '3.2.12'

gem "omniauth", "~> 1.1.1"
gem "omniauth-facebook", "1.4.0"

User model

def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| user.provider = auth.provider user.uid = auth.uid user.name = auth.info.name user.oauth_token = auth.credentials.token user.oauth_expires_at = Time.at(auth.credentials.expires_at) user.save! end end

Initialize/omniauth.rb

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, '51xxxxxxxxx42200', '0e3b1xxxxxxxxxxxxxxxxx4ff87'
end

Upvotes: 0

Views: 424

Answers (1)

beatlecz
beatlecz

Reputation: 158

You should have the app on your own domain. Heroku policy prevents creating cookies on *.herokuapp.com, check this: https://devcenter.heroku.com/articles/cookies-and-herokuapp-com

Upvotes: 0

Related Questions