Facebook Graph API and Docker - docker

Im working on a website using Laravel in a Docker container on local. The webserver used is Nginx.
Im trying to implement Facebook's Graph API (the PHP API) and as Im developing on localhost and using Docker, any time I want to use the API I get:
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 subdomains
of your app to the App Domains field in your app settings.
I tried adding the domain I use locally myapp.local:3000, also <my ip>:3000 or localhost:3000 but nothing works.
Here is the code:
public function facebookRequest() {
$fb = new \Facebook\Facebook([
'app_id' => 'MY_APP_ID',
'app_secret' => 'MY_APP_SECRET',
'default_graph_version' => 'v8.0',
]);
$callback = 'users/get-facebook-photos';
$helper = $fb->getRedirectLoginHelper();
$permissions = ['user_photos'];
$data['fb_url'] = $helper->getLoginUrl($callback, $permissions);
$loginUrl = $helper->getLoginUrl(base_url().'/users/get-facebook-photos', $permissions);
echo 'Log in with Facebook!';
}
What I need to do to develop using Graph API and Docker? There's some option to bypass domain filter or what should I do?

Seems like you're using your application to request a token from facebook servers and when the token is created, you'll end up being redirected on to the original destination. The redirect location cannot be "localhost" it should be a valid location ... like a website. If you want to make this work locally you could edit your /etc/hosts file to map local.example.com to 127.0.0.1 and use this domain for redirections in tests/QA, so that when your app gets redirected, it attempts it via the localhost.
Another suggestion (found by searching for the exact but more generic parts of the error "Can't Load URL: The domain of this URL isn't included in the app's domains") suggests:
add "https://apps.facebook.com/" in valid OAuth redirect URIs under https://developers.facebook.com/apps/your-app-id/fb-login/settings/

Well finally got a solution (not the one I wanted). I was using a custom domain defined on my host file. That didn't work for Facebook. I needed to use localhost (not even 127.0.0.1) and whitelist localhost on Facebook Developers.
So, if you have this issue, you can do this workaround and use localhost instead of custom domain. Nevertheless, my ideal solution would be using custom domains.

Related

Is it possible to share my localhost with someone on a different network?

I am working with a designer and I'd like them to have access to the interactions I've implemented on the site we're working on. However this time, I have 2 issues. My localhost is configured to a subdomain:
http://store.teststore:3000/ and we're on different networks. Is there anyway to work around this?
ngrok should work for you. Download and install it following these instructions here: https://ngrok.com/download. Documentation on how it is used can be found here https://ngrok.com/docs. Once installed running the below command should work for you (depending on the hosting environment):
ngrok http -host-header=rewrite store.teststore:3000
You will need to give the URL generated by ngrok and displayed in the cmd prompt to the designer.
Update: Handling absolute redirects
Based on your comment it sounds like, after login, your site does an absolute redirect (the full URL is specified). If it is possible I would change your code to do a relative redirect where the domain is omitted. You could also make your root domain configurable in the absolute redirect and configure it to be the ngrok domain provided for now. Lastly, you could attempt to configure your DNS with a CNAME record following ngroks Tunnels to custom domains documentation. This last option, however, requires a paid for ngrok subscription.
Install ngrok if you haven't yet and CD into your project directory and invoke ngrok. Note Your application must be running locally on the same port number ngrok will be running.

setting up subdomain in url locally

I am creating a rails application where we have functionality for registering a new User is there and there we are providing separate sub domain for each user by their user name.
so i want to map
user_name.localhost:3000.com where user_name is dynamic
Run your local development server with pow. If you symlink the app to the foo, than your pages are available under http://foo.dev, but also under every other subdomain like http://bar.foo.dev. There is no need to register a list of subdomains somewhere.
prax might be an alternative when you are on linux.
Access like this. No configuration required
user_name.lvh.me:3000
I have figured it out.
Actually the application is using subdomain_fu gem for creation of the subdomain and when the user is created the subdomain is name is saved in the db and the can accessed by making configuration into the file C:\Windows\System32\drivers\etc\hosts and map the ip which is being hit like ;
192.xxx.xx.xxx user_name.your_subdomain _name
and hit the url like this ;
user_name.your_subdomain _name:3000
It is working fine with me doing these steps.
Thanks to all for their valuable feed back.

Google API OAuth for Drive API is not working. Getting Error: origin_mismatch

I am trying to run the quick start code of Real Time API of Google Drive.
I believe I did everything right. But I am getting
Error: origin_mismatch
Request Details
openid_connect_request=true
cookie_policy_enforce=false
scope=https://www.googleapis.com/auth/drive.install https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/plus.me
response_type=token
access_type=online
redirect_uri=postmessage
proxy=oauth2relay601571239
origin=http://127.0.0.1
state=811328575|0.818765953
display=page
client_id=XXXXXXXXXX
You haven't given much detail about your application architecture, so i can only suggest a general answer. OAuth restricts which URLs can be referred to it. The list of permitted URLs is configured in the API console at https://code.google.com/apis/console. The URL is very fussy, so make sure you enter it exactly as it appears in the address bar.
As at Oct 2013, you can't use localhost. You have 2 choices.
edit 127.0.0.1 = mydevserver.example.com into your /etc/hosts
use a url shortener (eg. goo.gl) to create an alias to localhost
However, I believe that it is now possible to configure localhost in the
Google api console.
I had same problem with origin_mismatch.
From: Create a client ID section localhost should work and worked for me after small testing.
Origin in Google API i have:http://localhost
URL to address bar in browser:localhost
From the beginning this configuration not works, but after i tried write to address bar: 127.0.0.1->enter->origin_mismatch, it's correct and after again write localhost, now it's works.
Tested same behaviour in Firefox 39 and Google Chrome 37.0.2062.120 Ubuntu 12.04 (281580) (64-bit).

Twitteroauth with localhost

I currently have a website up and running that uses the Twitteroauth classes (abraham's) and the Twitter API. It is all working as it should, however, I want to also run the project on my localhost for debugging/coding purposes so that I am not in danger of messing up my live version.
I am wondering if it is possible to run Twitterouth on localhost. I know that there are ways to manipulate the callback URL of the application on Twitter's site, however I do not want to do that as my live version needs the callback URL.
I hope this makes sense and I hope there is a solution out there.
Thank you.
It is possible to run Twitteroauth in localhost. You should make a copy of your project files from your website and copy it to your localhost.
You might see a file "config.php" where you'll define the callback url.
define('OAUTH_CALLBACK', 'http://localhost/path_to_callback.php file');
It will redirect you to your callback.php file and it works in localhost.
For running Abramham William's twitteraouth locally , you can create another test application on twitter so that it don't disturb the live version . Then instead of using localhost/ in your address bar , you should use the IP address of your localhost , this mistake by me consumed a lot of time .
Example :
127.0.0.1/twittertest/index.php and not localhost/twittertest/index.php in your address bar .
You'll need to give the same oauth callback in your twitter application .

spring-social-vkontakte problems with authorizationCode

I try to develop an application with connection to social set vkontakte. To do this I use spring-social-vkontakte module of spring-social from https:// github.com/vkolodrevskiy/spring-social-vkontakte as this resources is mentioned in official site spring social http:// www.springsource.org/spring-social.
Problem is that when I use VKontakteConnectionFactory to make request to my application in vkontakte I can't use my local address in redirect_uri because I receive na error:
{"error":"invalid_request","error_description":"redirect_uri has wrong domain, check application settings"}
in vkontakte documentation http://vk.com/developers.php?oid=-17680044&p=Authorizing_Client_Applications in section how to build authorization url is described: "REDIRECT_URI – the address to which access_token will be rendered". To resole this problem I use http:// api.vkontakte.ru/blank.html as redirect_uri, I can receive an code but after authorization I can't back to my application. It is a problem. My example:
VKontakteConnectionFactory vKontakteConnectionFactory = new VKontakteConnectionFactory(app_id, app_secret);
OAuth2Operations operations = vKontakteConnectionFactory.getOAuthOperations();
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.setRedirectUri("http://api.vkontakte.ru/blank.html");
String authorazeUrl = operations.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, parameters);
response.sendRedirect(authorazeUrl);
In vkontakte I have created on application with next parameter:
Site address: http://localhost:8080/
Base domain: localhost (in this place I can't type localhost:8080, service denies it)
I destroyed some links because I can't post so many(
If somebody knows how to do redirection to localhost or some other solution how to solve this problem, please help me.
Thanks in advance
It does not allow you to specify domain 'localhost'. It should be a kind of 'localhost.ua', 'www.mysite.com'.
This has worked for me.
I am contributor of this project and updated its wiki https://github.com/vkolodrevskiy/spring-social-vkontakte/wiki

Resources