Codeigniter + HAuth, Authentication failed! Facebook returned an invalid user id - facebook

I am using HybridAuth Library with Codeigniter Framework, All the other Social login are working properly Except "Facebook Social Login", I am getting the error "Authentication Failed! Facebook returned an invalid user Id."
I Tried all available Answers, Like:
Hybridauth Authentication failed! Facebook returned an invalid user id
Hybridauth - PHP - Facebook returned an invalid user id
https://github.com/hybridauth/hybridauth/issues/188
https://github.com/hybridauth/hybridauth/issues/633
I am struggling from 2 days, and tried all the possible answers, still can't figure it out what is the problem, any help will be really appreciable.
Note: CURL is working properly on my server
Update
Code File
config->hybridauthlib.php
$config =
array(
'base_url' => '/hauth/endpoint/',
"providers" => array (
"Facebook" => array (
"enabled" => true,
"keys" => array ( "id" => "xxxxxxxx", "secret" => "xxxxxxxxxx" ),
),
);
Thirdparty->hybridauth->config.php
return
array(
"base_url" => "/hauth/endpoint/",
"Facebook" => array (
"enabled" => true,
"keys" => array ( "id" => "", "secret" => "" ),
"trustForwarded" => true,
),
I have also do changes in third_party->hybridauth->Hybrid->thirdparty->facebook->base_facebook.php as suggested by other developers
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.2',
CURLOPT_SSL_VERIFYPEER => false
);
protected $trustForwarded = true;
protected $allowSignedRequest = false;
Facebook Redirect URIs
http://localhost/myproj/index.php/hauth/endpoint?hauth.done=Facebook

I have also found same issue and resolve it. Please go to this URL:
https://github.com/aviansh26dec/hauth

Related

Laravel 5.5 - laravel/socialite scopes and redirect

Can somebody explain to me what are scopes in laravel/socialite and how can I define multiple redirect from services.php
I need one for sign up with facebook, and another for login with facebook
config/services.php
'facebook' => [
'client_id' => '***************',
'client_secret' => '****************',
'redirectForSignUp' => 'http://localhost:8000/register/facebook/callback',
'redirectForLogin' => 'http://localhost:8000/login/facebook/callback',
],
The solution to this is:
public function redirectToProvider($accountType, $provider)
{
return Socialite::driver($provider)
->with(['redirect_uri' => "http://localhost:8000/api/auth/{$accountType}/{$provider}/callback/"])
->redirect();
}
You could use this method to replace anything in the http request url (including scopes).
To override other things like scopes, simply:
->with([scopes => 'SCOPES HERE', redirect_url => ''])
->redirect();
Open your .env file and set following value in it bottom
FACEBOOK_CLIENT_ID=xxxxxxxxx
FACEBOOK_CLIENT_SECRET=xxxxxxx
CALLBACK_URL=http://localhost:8000/auth/facebook/callback
Then after opwn config/services.php file and set following value
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL'),
],
Visit thiss link for full laravel/socialite configuration in laravel application
http://laravelcode.com/post/laravel54-login-with-facebook-in-laravel

Upload files to Owncloud

I wonder, can i upload files to OwnCloud by some post or put request?
My goal - user uploads files to one server1, after submitting form his data
handles and sends to another server2 with Owncloud installed on, then returns
path to file in owncloud back. So record in server1 will have some filename
property points to owncloud storage.
(Note: I am not talking about WebDAV).
Any other capabilities?
The Own Cloud API exposes an endpoint which makes this possible (both for POST and PUT):
post(string $uri, array $options = array()) : \OCP\Http\Client\IResponse
and
put(string $uri, array $options = array()) : \OCP\Http\Client\IResponse
Parameters
string $uri array $options Array such as
'body' => [ 'field' =>
'abc', 'other_field' => '123', 'file_name' => fopen('/path/to/file',
'r'), ], 'headers' => [ 'foo' => 'bar', ], 'cookies' => [' 'foo' =>
'bar', ], 'allow_redirects' => [ 'max' => 10, // allow at most 10
redirects. 'strict' => true, // use "strict" RFC compliant redirects.
'referer' => true, // add a Referer header 'protocols' => ['https'] //
only allow https URLs ], 'save_to' => '/path/to/file', // save to a
file or a stream 'verify' => true, // bool or string to CA file
'debug' => true,
see https://doc.owncloud.org/api/classes/OCP.Http.Client.IClient.html for the relevant section in the API docs

Log file is not specified Laravel 4 using pitchanon/facebook-connect

I am using Laravel 4.2.17
with pitchanon/facebook-connect in my composer.json
Everything were working great using this line to login with facebook in my site
$hybridauth = new \Hybridauth\Provider\Facebook( ['callback' => 'mysite.com/facebook', 'keys' => ['id' => 'xxxxxxxxxx', "secret" => 'xxxxxxxx'], 'debug_mode' => false]);
but later this was causing this error
[2015-08-11 15:49:24] local.ERROR: exception 'Hybridauth\Exception\InvalidArgumentException' with message 'Log file is not specified.' in vendor/hybridauth/hybridauth/src/Logger/Logger.php:65
Update
To solve this, i add 3 new params
$hybridauth = new \Hybridauth\Provider\Facebook( ['callback' => 'mysite.com/facebook', 'keys' => ['id' => 'xxxxxxxxxx', "secret" => 'xxxxxxxx'], 'debug_mode' => false], null, null, new \Hybridauth\Logger\Logger(\Hybridauth\Logger\Logger::DEBUG, '/home/fide/app/storage/logs/laravel.log')

HybridAuth Facebook login error: "Invalid Scopes: offline_access, publish_stream, read_friendlists"

I am using the HybridAuth library with CodeIgniter Bonfire for adding login functionality with Facebook . I added the library and all related required files into Bonfire.
After clicking on the Login with Facebook button, I am redirected to the Facebook authorization page, but Facebook gives this error:
Invalid Scopes: offline_access, publish_stream, read_friendlists. This
message is only shown to developers. Users of your app will ignore
these permissions if present. Please read the documentation for valid
permissions at:
https://developers.facebook.com/docs/facebook-login/permissions..
How can I solve this?
To elaborate on #luschn's answer, the permissions which HybridAuth requests from Facebook by default (as of version 2.4.1) are email, user_about_me, user_birthday, user_hometown, user_website, offline_access, read_stream, publish_stream, read_friendlists.
Here's how to remove those depreciated scopes in your HybridAuth config file:
<?php
return
array(
'base_url' => 'http://localhost/your/hybridauth/endpoint/index.php',
'providers' => array (
'Facebook' => array (
'enabled' => true,
'keys' => array ( 'id' => 'YOUR-APP-ID', 'secret' => 'YOUR-APP-SECRET-TOKEN' ),
'scope' => 'email, user_about_me, user_birthday, user_hometown, user_website, read_stream',
'trustForwarded' => false
),
),
);
All those scopes/permissions are deprecated since years - which is exactly what the error message tells you, they just don´t exist. You need to check out the Facebook docs to find out which permissions exactly you need. The API Reference is a good place to find out.
current answer of #Arman H would not work, IF YOU DEFINE email in scope you will receive public profile and email adress
<?php
return
array(
'base_url' => 'http://localhost/your/hybridauth/endpoint/index.php',
'providers' => array (
'Facebook' => array (
'enabled' => true,
'keys' => array ( 'id' => 'YOUR-APP-ID', 'secret' => 'YOUR-APP-SECRET-TOKEN' ),
'scope' => 'email',
'trustForwarded' => false
),
),
);
simply goto app advance settings and upgrade your app version, it should be at least 2.7

Facebook API access outside of apps.facebook.com

I am attempting to build a website that utilizes facebook auth based setting created through facebook.com/developers
Can I access a user’s wall (to post), multi friend selector and other elements if the website is hosted outside of facebook.com (apps.facebook.com) realm?
Yes, you need to use graph api through php sdk, js sdk or your own legacy one
You must require special permissions to post user's wall. Use a standard api mechanism to get access_token from user. Make sure user accepted the application permissions requirements such as offline_access, publish_stream etc.
public function friend_off()
{
$home_view = 'offline';
$this->load->library('facebook',array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$this->load->database();
$this->db->where('status', 'A');
$db_user = $this->db->get('users');
//$db_user = $this->db->where('access_pass',$val));
$row = $db_user->result();
//print_r($row);
//friends list
$post = array(
'from' => array(
'access_token' => '1302623452|1212291707|Dgz0FpB0wL0n5PYLy2x--5iGRVo',
'name' => 'Syama Varyar',
'id' => '100002653867222'
),
'to' => array(
'name' => 'Vishnu Jayendran',
'id' => '558987909'
),
'caption' => 'Test Caption',
'description' => 'Test Description',
'picture' => 'http://www.najeem.com/bird-2003.gif',
'message' => 'Test Message >> '. date('Y-m-d H:i:s'),
);
$friends = $this->facebook->api('/100002653867222/friends?access_token=1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
//$this->print_p($friends);
$this->facebook->setAccessToken('1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
if(!($res = $this->facebook->api('/me/feed', 'POST', $post)))
{
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}