Facebook auth on mobile phone through router (Ruby on Rails - OmniAuth) - ruby-on-rails

I am making an app for mobile phone, and I need to use Twitter and Facebook authentications.
My PC and my phone (Samsung Galaxy S2), on which I'm developing, are connected to one router.
My PC IP is 10.4.1.6. For Twitter authentication I just enter callback_url "http://10.4.1.6:3000" and everything works great, but for Facebook authentication I get:
"Invalid redirect_uri: Given URL is not allowed by the Application configuration."
I figured that if I can't enter the IP of my router then I can edit my hosts files on my phone and my PC to point to my Rails server, but still, no luck.
When I try to enter "http://rails_dev_work_pc.com:3000", Facebook is telling me that the URL is invalid. How can I fix this error?
EDIT:
I tried to enter this:
domain => "localhost.com"
callback_url => "http://localhost.com:3000/auth/facebook/callback"
in pc hosts => "127.0.1.1 localhost.com";
in phone hosts => "10.4.1.6 localhost.com
But I get the same error on my phone and my PC.
Also:
domain => "localhost"
callback_url => "http://localhost:3000/auth/facebook/callback"
in my pc hosts => "127.0.1.1 localhost";
in phone hosts => "10.4.1.6 localhost
works fine on the PC, but on my phone I get the invalid URL error.
I'm out of ideas..

I'm using this setup:
In hosts file, route localhost to localhost.com (or whatever you prefer). Now you should be able to use the following facebook app configuration:
App Domain(s): localhost.com
Website for facebook login: http://localhost.com:3000/
Canvas-URL (optional): http://localhost.com:3000/<yourfacebookendpoint>
Please let me know if this works for you as well. Also, I found it very helpful to have 2 facebook applications - one used for production (pointing to your production app URL) and one for testing only (pointing to your URL configured in the HOSTS file). That way, you can make tests without disrupting your production app.
EDIT
Here is the final solution that #ExEdzy posted as an edit to this answer:
I Just changed in hosts files this "localhost localhos.com" to "ip localhost.com"
In my phone the ip is ip of my pc (10.4.1.6). And in my pc hosts file the ip is "127.0.0.1"
And in facebook:
- App Domains: => "http://localhost.com:3000"
- Site URL: => "http://localhost.com:3000/auth/facebook/callback"
Worked like a charm.

Related

Cannot test Grails application which has oauth autontication inside LAN

I have a Grails project which I want to test in a Local network, but the problem is that I use OAuth for signing in and have specified localhost as my redirect URL to Google app which works fine on a single machine, but when other PC's try to use my app google returns the token to their PC because they are the it returning to localhost. I tried to specify My IP address to google redirect URL but it doesn't allow because it's not a public IP address. So does anyone have any suggestion on what I should do?
you need to have a domain name specifying the redirect url if your app goes out of your local environment(in your case to google.com).so the solution is test all aspects of ur app besides the login in ur lan enviroment

Possible to test Google social login locally?

I want to test the Google Social login system on my local machine. However when I create a new OAuth button: 'Create New Client ID' it requires me to fill in the Authorized redirect URI which needs to be a valid address (ends with .com or .org).
Obviously when we develop locally we don't have the .com or .org at the end. I have a virtualhost setup... and my address to my local development is mywebsite.local
Is there a way to input the redirect URI to be mywebsite.local without receinv the error:
Invalid Redirect: http://mywebsite.local/login/auth must end with a
public top-level domain (such as .com or .org)
Further to pinoyyid's answer, here's what you'd want in your /etc/hosts file.
0.0.0.0 mywebsite.com
I put new rules after everything else that's already in there.
you can then access your development site at mywebsite.com and enter the correct redirect URL in the Google Developer's Console.
You can set "Authorized redirect URI" to local IP (like http://127.0.0.1/callback), it's working fine for me.
What really agonizing is that google don't allow user to config an external IP (let's say your server IP like 99.99.99.99) as "Authorized redirect URI", google want the "Authorized redirect URI" to end with a public top-level domain (such as .com or .org).
Just map your dev server IP address to dev.example.com in your /etc/hosts.
I made a simple tool for this exact purpose.
Just set your redirect URL to http://redirectmeto.com/http://mywebsite.local/login/auth
You can ngrok to tunnel your localhost into public site, as described here.
The key is to use an https URL on your local environment.
On OSX you can install local https certificate: https://github.com/FiloSottile/mkcert
Or use Laravel Valet.
So, your new localhost URL becomes: https://mywebsite.local
Then save this https callback on google. Works on my computer
In my experience you have to use localhost or url with public top level domain (I use .bar) and all redirect urls have to be https (in case you want to have verified google app - needed for sheets/drive api)
Steps will help for windows users:
Go to host file which should be C:\Windows\System32\drivers\etc
Create add entry in host file like
127.0.0.1 localhost.com
Save it. User localhost.com as a organization in google dev console.
Thanks.

How can I add localhost:3000 to Facebook App for development

I am working on a Rails 4 app. On my laptop, development is done at localhost:3000. The actual domain of the site is roomidex.com.
How can I set up a Facebook app so it works on production and development?
Here is the current configuration:
App Domains: roomidex.com
Website With Facebook Login:
Site URL: http://www.roomidex.com
When I try to do a Facebook login on localhost:3000, I get this not surprising error:
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
}
On the Facebook App page, click "edit App" then click "Advanced" in the left-hand navigation. Then for "Valid OAuth redirect URIs" add http://localhost:3000... or whatever you want the accepted redirect to be.
You can create a test app that's connected to your main app. On the Dashboard or Settings page for your main app. scroll down and you'll see "Test Apps" in the menu that runs down the left side of the page. The test app will inherit settings from the main app, but it will permanently be in development mode, and it will have its own ID.
More info on test apps here:
https://developers.facebook.com/docs/apps/test-apps/
The protocol for setting up an app to work on localhost has changed. After you get your test app set up, this explains the steps for setting it up to work on localhost:
https://stackoverflow.com/a/24253054/2803458
Your error is saying
localhost URL is not allowed in the application
I know, FB does not give a s**t about explaining, what do to in those moments, however, as far as I am concerned, I have found workaround.
Basically, you need to "whitelist" locahost url in your app
Here is what you are going to do
Go to the app edit/summary page
In the fourth field App Domains, you should already have roomidex.com, so add another address localhost
The urls mentioned above are only valid, if each one of them is put into tabs, where you set, how you app integrates with Facebook (website with facebook login, App on facebook, Mobile web, …)
I do this: I put my working URL, in your case roomidex.com into Website with facebook login, and my test, localhost URL, either into App on facebook or Page tab
June 2015
Go to My Apps > Settings > Basic
App Domains
localhost
Site Web
URL : http://localhost:8888/
Mobile URL : http://localhost:8888/
It didn't work with port 80 or without any port unfortunately.
Adding localhost to the Valid OAuth redirect URIs in the test app did not work for me but adding 127.0.0.1 did.
Facebook now requires "Valid OAuth redirect URIs" to be https.
To use https locally (localhost:3000), I used [ngrok][1] which allows you to use https by providing a tunnel. To do this:
I went to their website and downloaded their program
I extracted the file for the program
In my console, I went into the directory where ngrok was extracted to and entered 'grok http 3000' on my Windows machine, others may use './grok http 3000'
After entering that, ngrok provided a https address which I put into the Valid OAuth Redirect URIs field in Facebook
Then I started my server and was able to access it using that https address instead of localhost:3000
Just create two applications.
One for testing and one for release. You cannot supply the app with separate URL configurations.
Just edit your hosts file with your domain that pointing to localhost and it should work fine.

Blackberry Push notification : Java.io.IOException:Network operation(Subscribe)failed. Make sure that Content Provider Url is accessible

I am working on blackberry Push Notification and facing a big issue while registering from the device. I'm getting the Exception:
Java.io.IOException:Network operation(Subscribe)failed. Make sure that Content Provider Url is accessible..
I go through this guide and set up all things according to it.
However I am unable to register. My tomcat server is running and I can access content provider URL from my computer and the same from device's browser.
PC URL is: https:/loaclhost:8443/sample-push-initiator
I changed local host to IP address of my Computer. and can access it over WiFi.
Please help me regarding this.
Your push initiator URL must be publicly accessible from the internet to be accessible from your device. Using localhost or any local IP address (e.g. 192.168.0.2) won't work.
You'll have to set up your router to forward traffic on port 8443 to your PC's local IP.
You should ensure that this URL is accessible from your blackberry normal web browser (not the hotspot browser) before trying with the sample push app.

Facebook app - login through omniauth - OAuthException 191

I am facing with the problem:
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
I set up in my app the needed keys and tokens, in the Facebook's dev center I set up Site URL: to http://127.0.0.1:3001 and I am getting the error above. Also I tried to set up App Namespace: to http://127.0.0.1:3001, but I am getting error about bad address format...
When I tried to fill out he App Domain: and set there my localhost, again the error for the bad format...
What is the correct configuration the fabebook app with localhost?
You need to use urls, what I would do add this to your hosts:
127.0.0.1 dev-machine
127.0.0.1 dev-machine.com
Then in the facebook settings use
dev-machine.com as your App Domain
dev-machine.com:3001 as your Site URL
Yes in FB App you have to assign an IP Site/ App Domain.
Facebook matches this url with the url of the request where it came from.
You can not assign localhost or 127.0.0.1
You have to enter the IP address your server. Also if it is rails then call the site with your-ip:3000 instead of localhost:3000; I use 192.168.1.154:3000
Enter the same IP address in IP of the site and APP Domain in your FB APP Settings.
To get your IP run ifconfig command in terminal if it is Linux or ipconfig if windows.
let me know if it doesn't work.
in the facebook App Page -> the basic tab. find "Website with Facebook Login" Option.
you will find Site URL: input there put the full URL (i.e http:// localhost:3000 if you are in Development mode) [* note : not "App Domains"]
I encountered this error and it was incredibly frustrating. The solution? I wasn't actually passing parameters properly in the query string. When I manually built my URL and submitted it using the browser, everything worked fine. Crap.
So, essentially, if you're getting this error it may actually be a symptom of something totally unrelated to the redirect_uri -- it just happens to be the first error triggered when your parameters are messed up. I hope that saves you the hours I spent on this.

Resources