Facebook Login from a non hosted web page - javascript

I am creating an hybrid app totally based on Html, CSS and Javascript.
I want to add facebook login functionality but as the web page isn't hosted any where i keep getting the warning message :
Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
Also clicking on the login button opens up a blank window.
Following this tutorial:
https://developers.facebook.com/docs/facebook-login/login-flow-for-web/
I am not using Phonegap , sencha or any other framework.
Is there a way I can achieve this?

You need to specify an authorised domain in order to use the Facebook SDK, because your HTML only sits on the handset, you don't have a domain.
Have a look at Parse. Parse is a framework built for Facebook integration within mobile applications.
https://parse.com/docs/js_guide#fbusers-signup
The other option is host the HTML, CSS and JS on a server and pull the content into the app through a WebView, this will allow you to have a domain that you can add to your App settings page.

Related

Share cookies between flutter webviews

I'm developing a flutter app with Webviews using this plugin: Flutter_inappwebview.
At first, I am loading a webview with the login page in a own domain and later redirect users to a different domain url. On this second url I inject an iframe menu loaded from the same site where the user was logged before. I need the login cookies accesible on this iframe, but i can't get it working.
Menu is loaded and the cookies exists, but the menu injected with an iframe in the second domain doesnt' works.
By the way, i need a way to communicate between javascript loaded in the url and a flutter webview. I tried with the services included in the plugin, but doesn't work.
Thanks for your help =)
You can use the cookies_jar package available for flutter to achieve the behaviour you are expecting.

Communicate w/ Javascript running in an iFrame

I'm currently working on an application that uses the Phonegap/Cordova framework to display an online and an offline version of a website. If you're not familiar w/ this framework, it offers a simple way of creating multi-platform applications by displaying local files in a full-screen webview.
When launching the application, the Javascript integrated in the local files of the application detects if Internet access if available, and redirects the user to either another local webpage containing a full-screen iFrame of the live website, or a reduced offline version of the website (contained in the local files of the app) if no Internet connection is detected.
I would like to detect when the user logs in using the various forms on the website (being displayed inside the iFrame), but I have no way of knowing which page the user is on, or interact w/ the website content at all because of the same-origin policy.
Would it be possible though to make the Javascript from the local page (which contains the iFrame) interact w/ the Javascript from the remote page (which is being displayed in the iFrame)? This way, I would be able to obtain the login information, and save it for later use (obviously not w/o using a token system), but also it would help for another planned feature (trigger the guidance system).
Thank you.
Look into HTML5 communication, it's pretty simple and sounds like it fits your needs
http://stevehanov.ca/blog/index.php?id=109
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

Deep link to my Mobile App from my Website Using App Links approach

I am trying to use the App Links Meta data to add support to deeplink our mobile App from our mobile Web pages and looks like I hit a road block on my first step. The documentation states that the meta tags be included in your head section of the page. App Links Doc
<head>
<meta property="al:ios:url" content="mysite://docs" />
<meta property="al:ios:app_store_id" content="12345" />
<meta property="al:ios:app_name" content="My Site" />
</head>
Can the meta tags be used only for Facebook and Twitter currently or any site can take advantage of it
I see that there are many tutorials out there on how to handle the URL's once they hit the IOS or Android App. But I see no info on how this is supposed to be handled on the web site in general( on where it is deeplinked to the mobile App)
So is including the meta tags the only step required to deep link ?
Or Do we need to write up some javascript based on some action depending on the device the user is in needs to be redirected to one of the url's that the Mobile App is configured to ?
Like specifying the window.location = 'mysite://help' and rerouting to web url if that fails.
As of now the documentation does not seem to be really clear on how to handle this on the web side of any application.
First
facebook Document says
You can add support for App Links to existing web content by defining metadata that details how apps link to your content. You need to add the following information to your URLs:
So definitely it can for any site.
Second
just include meta tags will be fine.
but something to notice:
facebook applinks doc says
App Links is an open standard that makes it possible to deep link to content in your app. When someone using your app shares content via Facebook (or another App Links-enabled app) you can create a link that makes it possible to jump back into your app from that piece of content.
and when you test your link on your wall, it will be cache.
so when you change your html, you should go to debugger to fetch again.
you can create an applink here: https://developers.facebook.com/quickstarts/?platform=app-links-host
the iOS url is a url that cna be used to launch you iOS app - e.g. a schema (app://) used for deeplinking.
this will create a fb.me/xxxxx link which you can use as the app linkin your code.
If you're creating a standalone web app (as your question tags suggest) then there's no way to launch it programatically, at the moment. Home-screen web-apps must be launched by the user.
App Links only works between websites and App Store apps, it won't work to launch web apps.
I've seen discussions of the Chromium developers talking about adding this feature (https://code.google.com/p/chromium/issues/detail?id=468226) so hopefully it will appear on Android/Chrome soon, and – fingers crossed – Apple will follow suit one day.

Facebook App: localhost no longer works as app domain

I've been writing a game for Facebook using Rails and jQuery. Since I started using the Facebook Javascript SDK, using localhost as an app domain seemed to work just fine. I was able to test my game both locally and on Heroku.
In the past day, it seems that Facebook has made a big update to their developer UI. Now if I add localhost as an app domain, it gives me the following error:
This must be derived from Canvas URL, Secure Canvas URL, Site URL, Mobile Site URL, Page Tab URL or Secure Page Tab URL. Check and correct the following domains: localhost
My game also now doesn't work locally and I get an error when the Javascript SDK logs in the user:
API Error Code: 191 API Error Description: The specified URL is not
owned by the application Error Message: Invalid redirect_uri: Given
URL is not allowed by the Application configuration.
This doesn't happen when I deploy my game, since herokuapp.com is considered a valid app domain.
How am I supposed to develop and test my game if I can no longer use localhost or 127.0.0.1?
The protocol seems to keep changing, and the accepted answer didn't work for me today. In case it helps other searchers, this is what did work for me:
All changes were made on the Settings page under the Basic tab
1.) In the center under the first box of options, click "+ Add Platform" and choose "Website" (or whatever is appropriate for your app.)
2.) In the box that comes up for the website you just added: Site URL: http://localhost:3000/
3.) In the box above that (Settings => Basic): App Domain: localhost
4.) At the bottom right - click "Save Changes"
5.) Make sure you have the app ID copied and pasted correctly into your code. (The ID is in the first box on that page if you need it again.)
Go to your App's settings page in http://developers.facebook.com
Click on the dropdown arrow on the top left (next to the name of your app) and click "Create Test App" and give it a name
In the Settings > Basic of that new Test App set the App Domains as "localhost"
Also set the Website Site URL as "http://localhost:8888" (or whatever port you are using).
IMPORTANT: this app has different App ID and App Secret from your online application. So, last step: make sure that you update the code that sits in your localhost with the Test App's App ID and App Secret. On the contrary, the code that sits in the live server should be using the main App's ID and Secret.
You can still test your app without deploying it on a remote sever like heroku.
The trick is to update the etc/hosts file this way:
127.0.0.1 mydomain.com
Then on the Facebook App's settings, type [http://] mydomain.com, without the "[" and "]"
It worked for me this way
For everybody who is fidgeting with this in 2017. The interface changed again. I wanted to comment this to the answer but I don't have enough reputation. The localhost url of your app now has to be copied to three places. Currently, (October 26th, 2017) the sequence is:
1.) Click "Settings" in the left menu.
2.) In the center under the first box of options, click "+ Add Platform" and choose "Website" (or whatever is appropriate for your app.)
3.) In the box that comes up for the website you just added copy your localhost site url (f.e. http://localhost:3000/)
4.) In the box above that "App Domain" copy the same URL
5.) At the bottom right - click "Save Changes"
6.) In the left menu under "Products" click "Facebook Login" (or add it via "+ Add Products" if it is not available)
7.) You are now in the Facebook Login settings. Copy the same url to the field "Valid OAuth redirect URIs"
This should work.
Just add localhost as your canvas url or mobile site url, this will allow you to have both localhost and herokuapp.com in your App Domain setting. Then once your app is in production, just remove it.
This is wrong way. You must create a test application using Test tab in app settings. And then you can enter your development stage url (for example localhost) to your application.
Solution using Firebase
In order to get this working on localhost, port 3000 I did the following:
Create App
Now Select "+ Create Test App" from the arrow dropdown (top left).
Add localhost to App Domains
Add http://localhost:3000/ to Site URL by selected "+ Add Platform"
Up to this point I had followed all previous answers submitted on here, but nothing worked.
So...
In the left hand menu, select "Add Product"
Add "Facebook Login"
You will be presented with a workflow carrousel, with defaulted domain http://localhost:3000/, click "continue" until the end.
Select "Facebook Login > Settings" from the Product Menu.
Enter your Firebase OAuth redirect URI (found when enable Facebook Login in your firebase console https://console.firebase.google.com, example below)
Paste URI and Save.
Done.
Try using the url with port, e.g.
http://localhost:8000/
I was having the same issue and found this solution right now.
After straggling with this for a while I found a solution that combines few answers from this question. I guess that things constantly change when it comes to things like Facebook apps.
The following worked for me at the time of writing.
The key takeaways are:
You must use HTTPS in your backend. You may use a self-signed
certificate.
To test against localhost you must create a test app from your primary app
TL;DR
Make sure your server exposes an HTTPS enabled port with a self-sign certificate. Consult your server documentation.
Go to https://developers.facebook.com/apps and select "Create App".
Select app type that supports Facebook login (E.g. consumer), click continue
Set a display name and contact email and click "Create App"
Optional! When the prompt to Add Products to Your App choose Add Facebook login. Here you will set your production login setting with a real domain, but you can focus on tests app at this stage.
Go to the left side of the page where your app name is displayed. In
the select box and click the small arrow. When the select box expand
click the button "Create Test App"
On the create test app popup select "Create Test App"
On the newly created test App go to "Add a Product" and "Add Facebook login" by clicking "Set up"
Ignore the setting by selecting the settings list under the "Facebook Login" on the left side of the page.
Note the info message at the top "You are currently editing a test version of ..."
Verify that both Client OAuth Login and Web OAuth Login are enabled (blue yes)
Under the "Valid OAuth Redirect URIs" add your local HTTPs address e.g.
https://localhost:8443
Click save changes.
Click Setting basic on the left side of the page and copy your
App Id and App Secret and keep them in a safe place
Common pitfalls
Make sure that you use your test app secrets when you test and not the main app, resulting in the following error
Can't load URL
The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
Make sure you use https://localhost:8443 and not https://127.0.0.1:8443 those are not the same from OAuth point of view resulting in an error similar to the one below
URL blocked
This redirect failed because the redirect URI is not white-listed in the app's client OAuth settings. Make sure that the client and web OAuth logins are on and add all your app domains as valid OAuth redirect URIs.
This works for me in heroku, the localhost thing didn't work (for me). I hope it helps
1.) In the center under the first box of options, click "+ Add Platform" and choose "Website" (or whatever is appropriate for your app.)
2.) In the box that comes up for the website you just added: Site URL: http://MYAPP.herokuapp.com/ (replace MYAPP with the name of your app)
3.) In the box above that (Settings => Basic): App Domain: MYAPP.herokuapp.com (replace MYAPP with the name of your app)
4.) At the bottom right - click "Save Changes"
Just a note for some others who may be struggling with this as I was. I have not been able to get this to work with "test" apps. Using my actual app settings (and simply adding
"http://localhost:3000/"
to my canvas URL) worked as everyone else suggested. It seems test apps aren't equal to actual apps.
I ran into an issue with my Rails app that I usually run with http://localhost:3000 because Facebook now requires the Valid OAuth redirect to use https.
To use https locally, 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
to do local testing all you have to do is turn off the app, or put the facebook app in development mode. Then Facebook will allow you alone to access the app
For me it worked like this:
Configuring the facebook app dashboard:
*On the ' basic ' tab:
1) Leaving app domain empty.
2) Erasing any platform. Meaning: no website no canvas platform. (so no site-URL field to fill)
*On the 'advanced' tab:
3) I entered into the Valid OAuth redirect URIs:
http://localhost/myappfolder/redirect.php
4) regarding my code,
insdie my c:/xampp/htdocs/localhost/myappfolder/index.php (this file makes the loginURL):
$helper = new FacebookRedirectLoginHelper('http://localhost/myappfolder/redirect.php');
inside the redirect.php file:
$helper = new FacebookRedirectLoginHelper('http://localhost/myappfolder/redirect.php');
and I got a session! finally! no need to hang myself in the end :P
For those still having this issue, make sure your app is in development mode while trying to use localhost as the app domain else it won't work.
In case you are using Hotwire, remember to use button_to instead of link_to and disable Turbo on it. E.g:
<%= button_to "Register with Facebook", user_facebook_omniauth_authorize_path, form: { "data-turbo" => "false"}, method: :post %>

Phonegap Facebook connect plugin settings

I'm using phonegap plugin to connect to facebook
this one : https://github.com/phonegap-build/FacebookConnect
I'm confused about Facebook app settings, when I call FB.init() I get this error message:
Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
I edited Website with Facebook Login (site url) to : http:// localhost/ (without the space ofcourse I only added it because stackoverflow doesn't allow a link with 'localhost' in it) and I waited for several minutes (more than one day) for it to work but it's still not working.
any idea how can I get it to work ?
thanks
There are several settings which you need to set.
These settings worked for me for a Phonegap Build environment.
Under Native Android App:
package name: the "widget id" you have in your config.xml (e.g. com.aaa.bbb)
class name: the "widget id" with ".ProjectActivity" appended (e.g. com.aaa.bbb.ProjectActivity)
key hash: generate the key hash using the android instructions. Facebook explains this at https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/
facebook login: enabled
deep linking: disabled
Other steps:
You don't need to set "Website with Facebook Login (site url) " to http://localhost/ anymore. If you have a real website (with facebook login), then that's the place to put the real website URL.
Ensure sandbox mode is disabled
Write this code in onDeviceReady after creating your application id on facebook
FB.init({
appId: "<your appId>",
nativeInterface: CDV.FB
});
on facebook eit your app settings
set your "Website with Facebook Login" to
http://localhost/

Categories