Frankie
Frankie

Reputation: 1

Facebook Invalid Redirect URI for www.domain.com and not domain.com

I have a rails app that is on heroku and I have it at a custom .com domain name. I have my facebook app canvas url set to domain.com and when I hit login with facebook it works but when I got to www.domain.com it gives me:

{
   "error": {
      "type": "OAuthException",
      "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration."
   }
}

How would I fixed this in heroku?

Upvotes: 0

Views: 1936

Answers (5)

Tsuneo Yoshioka
Tsuneo Yoshioka

Reputation: 7874

If you want to redirect keeping current path, you can write like below in application_controller.rb .

class ApplicationController < ActionController::Base
  before_filter :check_uri

  def check_uri
    if request.host == "xxx.herokuapp.com" then
      redirect_to request.protocol + "www.xxx.com" + request.fullpath
    end
  end

Upvotes: 0

thatdankent
thatdankent

Reputation: 950

This is the only solution I could find for heroku that did not lead to infinite redirects or other problems. Hope it helps.

Force 'www' in Rails3 hosted on Heroku without .htaccess

Upvotes: 0

colinhl
colinhl

Reputation: 11

Codeglot's didn't quite work for me, but using his elements, this did.

In your application_controller put:

before_filter :check_url

#redirecting the herokuapp and www version of domain
def check_url
  url = request.url
  if url.include?('appname.herokuapp.com')
    redirect_to ('http://domain.com')
  elsif url.include?('www.domain.com')
    redirect_to ('http://domain.com')        
  end    
end

If you are using bamboo instead of cedar, then replace "herokuapp" with just "heroku"

Upvotes: 1

iwasrobbed
iwasrobbed

Reputation: 46703

I would just set up a URL Redirect record on your domain host (GoDaddy, NameCheap, etc.. whoever you bought the domain name through) to redirect all www.yourapp.com to yourapp.com so this all happens at the DNS server before it even gets to your app server.

Here's a similar question I answered recently dealing with this (that answer is for the opposite case when they wanted all yourapp.com requests to redirect to www.yourapp.com but its the exact same idea): Redirecting subdomain for static assets on Heroku

By the way, this method will automatically redirect them to whatever path is appended onto the end as well. So hitting www.yourapp.com/something will redirect them to yourapp.com/something

Upvotes: 0

Sam 山
Sam 山

Reputation: 42865

You need to add www.domain.com and domain.com to the facebook API or have a redirect in your controller that redirects if you are at www.domain.com

 before_filter :ensure_domain
 before_filter :get_filter

   def ensure_domain 
    url = request.url
    if url.include?('domain.heroku.com')
        redirect_to url.gsup('domain.heroku.com', 'domain.com')
    eslif url.include?('www.domain.com')
        redirect_to url.gsup('www.domain.com', 'domain.com')        
    end    
   end

Make sure the url are getting substituted correctly but that should do it.

Upvotes: 0

Related Questions