Undefined index: client_id while using Laravel 5.1 / Socialite / Dropbox SDK - php

So I've realized that Laravel 5.1 can't use sessions to store the CSRF token required by the Dropbox SDK when authenticating a user via OAuth2. To get around this, I've followed this great post to use this provider and Laravel Socialite to make the OAuth2 calls for me but, even after following that doc to the letter, I'm still getting the following error:
ErrorException in SocialiteManager.php line 91: Undefined index: client_id
I can't find where client_id would even be an index in the flow so I'm thoroughly confused on this one. Any help would be great appreciated.
Here are the methods that are being fired to evoke the Socialite/Dropbox service provider:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
// other Classes
use App\User;
use Hash;
use Input;
use Auth;
use DB;
use Socialize;
class UserController extends Controller
{
public function showDropbox()
{
return Socialize::driver('dropbox')->redirect();
}
}

It was something very simple and a complete oversight on my part... I had the wrong indices in the config/services.php file that the tutorial required.
I had...
'dropbox' => [
'redirect' => env('DROPBOX_REDIRECT_URI'),
'key' => env('DROPBOX_KEY'),
'secret' => env('DROPBOX_SECRET'),
],
...when I should've had:
'dropbox' => [
'redirect' => env('DROPBOX_REDIRECT_URI'),
'client_id' => env('DROPBOX_KEY'),
'client_secret' => env('DROPBOX_SECRET'),
],
Hope that helps someone!

Related

Twitter API asatymic/twitter with Laravel 8

I followed his readme and I have done composer dump-autoload a million times, but still I receive an error. Don't know what i am making wrong. I am trying to use v2 version of twitter api. Please help me anyone.
In config/app.php:
'providers' => [
...
Atymic\Twitter\ServiceProvider\LaravelServiceProvider::class,
],
'aliases' => [
...
'Twitter' => Atymic\Twitter\Facade\Twitter::class,
],
In my controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Twitter;
class HomeController extends Controller {
public function index() {
$tweets = Twitter::getUserTimeline([
'screen_name' => 'xxxxxxx',
'count' => 10,
'format' => 'json'
]);
dd($tweets);
return view('home');
}
public function about() {
return view('about');
}
}
But I am getting this error:
Error
Call to undefined method Atymic\Twitter\Service\Accessor::getUserTimeline()
Look like you have to import facade
Instead of this
use Twitter;
Import this
use Atymic\Twitter\Facade\Twitter;
If you are using alias then run following command
php artisan config:clear
composer dump-autoload
php artisan optimize
Please look to the twitter api version which you have defined in the .env. you may need to use 1.1 and you are using v2
I think getUserTimeLine is available for version 1.1, and I think as the readme says you can use userTweets for v2

RuntimeException - Session store not set on request - Laravel Socialite - Facebook

I'm using Laravel 5.7 and Laravel/Socialite 3.1.
I want to login using a Facebook app I just configured for this project.
These are the main files I have configured for this:
/.env
...
FACEBOOK_CLIENT_ID=***
FACEBOOK_CLIENT_SECRET=***
FACEBOOK_CALLBACK_URL=http://localhost:8000/auth/facebook/callback
/config/services.php
<?php
return [
...
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('FACEBOOK_CALLBACK_URL'),
],
];
/routes/api.php
<?php
use Illuminate\Http\Request;
...
Route::get('auth/facebook', 'SocialiteController#redirectToProviderFacebook');
Route::get('auth/facebook/callback', 'SocialiteController#handleProviderCallbackFacebook');
/app/Http/Controllers/SocialiteController.php
<?php
namespace App\Http\Controllers;
use Socialite;
class SocialiteController extends Controller
{
public function redirectToProviderFacebook()
{
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallbackFacebook()
{
$user = Socialite::driver('facebook')->user();
print_r($user->token);
}
}
My problem is that for some reason I get the error:
RuntimeException
Session store not set on request.
as you can see on the following image:
I don't want to use sessions on this project at all. I just want to get the token from Facebook on the callback inside: function handleProviderCallbackFacebook().
Any idea on how to solve this issue?
Thanks!
From the Socialite documentation
The stateless method may be used to disable session state verification. This is useful when adding social authentication to an API:
return Socialite::driver('google')->stateless()->user();

CakePhp 3 Plugin Authentication adapter was not found

I'm kinda a newbie in Cakephp (3.5) and I'm currently trying to make my first plugin (called Example) which contains several sub-directories. One of them is the UserManager directory which contains a Users MVC standard suit with authentication.
Since I want to add social logins and other stuffs, I created my own auth component as explained in the docs :
plugins/Example/UserManager/src/Controller/AppController.php
<?php
namespace Example\UserManager\Controller;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Example/UserManager.Example' => [
'fields' => ['username' => 'email', 'password' => 'pass'],
'userModel' => 'Users',
],
],
]);
}
}
plugins/Example/UserManager/src/Auth/ExampleAuthenticate.php
<?php
namespace App\Auth;
use Cake\Auth\BaseAuthenticate;
use Cake\Http\ServerRequest;
use Cake\Http\Response;
class ExampleAuthenticate extends BaseAuthenticate
{
// The same as Form authentication, since I'm testing
}
The problem is that I can't make the authentication component find the ExampleAuthenticate class. I already tried by setting the authenticate config param like
Example
ExampleAuthenticate
UserManager.Example
Example/UserManager.Example
Example\UserManager.Example
Example/UserManager.ExampleAuthenticate
Example\UserManager.ExampleAuthenticate
but I always get the error Authentication adapter "..." was not found. when visiting http://localhost/Project/example/user-manager/users :(
Does anyone have any clue of what I might be missing?
The problem was that the php function class_exists(...) didn't recognise the custom authentication class, so after digging a bit more I realised that the namespace shown in the docs only works for a custom authentication file defined in the App environment, but not in the Plugin one (silly me).
So I changed namespace App\Auth; to namespace Example\UserManager\Auth; inside ExampleAuthenticate.php and it worked like a charm! now the function class_exists('Example\\UserManager\\Auth\\ExampleAuthenticate') returns true and everything works perfect by defining Example/UserManager.Example in the authenticate config params.

Class 'Paypal' not found in laravel

<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Paypal;
use Redirect;
use Illuminate\Http\Request;
class SubscriptionController extends Controller
{
private $_apiContext;
public function __construct() {
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
}
I'm getting an error that
Class 'Paypal' not found
in SubscriptionController.php line 17
But my IDE shows that it's there, I even used it in another project and its working fine.
In my app.php I have:
'Paypal' => 'Netshell\Paypal\Facades\Paypal',
So it should be good.
Why do I get that error?
Run this command in your Laravel project root to install Paypal composer require netshell/paypal dev-master
After that, add the service provider to app/config/app.php in the providers array.
'providers' => [
// ...
'Netshell\Paypal\PaypalServiceProvider',
]
At the end, add an alias to app/config/app.php in the aliases array
'aliases' => [
// ...
'Paypal' => 'Netshell\Paypal\Facades\Paypal',
]
After that you should be able to use Paypal
Hope it helps
Try getting rid of the use Paypal; line. If you are defining an alias in app.php, I don't think you need a use statement for it - that has been my experience when defining my own aliases.
You can also try defining your alias with a different syntax to see if it helps:
'Paypal' => Netshell\Paypal\Facades\Paypal::class
(notice there are no quotes on the value as it is a reference to a class).
php artisan config:cache fixed it.
Have you tried doing use \Paypal;?

Unable to use Laravel / Socialite with Lumen

I try to use the package Laravel\Socialite in my system in Lumen (5.1)
I added this in the config\services.php file :
<?php
//Socialite
'facebook' => [
'client_id' => '##################',
'client_secret' => '##################',
'redirect' => 'http://local.dev/admin/facebook/callback',
],
In bootstrap\app.php file :
class_alias(Laravel\Socialite\Facades\Socialite::class, 'Socialite');
$app->register(Laravel\Socialite\SocialiteServiceProvider::class);
Then I created a controller for the facebook authentication :
<?php
namespace App\Http\Controllers\Facebook;
use App\Http\Controllers\Controller;
use Laravel\Socialite\Contracts\Factory as Socialite;
class FacebookController extends Controller
{
public function redirectToProviderAdmin()
{
return Socialite::driver('facebook')->scopes(['manage_pages', 'publish_actions'])->redirect();
}
public function handleProviderCallbackAdmin()
{
$user = Socialite::driver('facebook')->user();
}
}
And in the routes.php :
$app->get('/admin/facebook/login', 'App\Http\Controllers\Facebook\FacebookController#redirectToProviderAdmin');
$app->get('/admin/facebook/callback', 'App\Http\Controllers\Facebook\FacebookController#handleProviderCallbackAdmin');
I just followed the documentation, changing according to my needs. When I go to page http://local.dev/admin/facebook/login, I get the following error :
Non-static method Laravel\Socialite\Contracts\Factory::driver() cannot be called statically, assuming $this from incompatible context
Indeed, according to the code, driver function must be instanciate.
EDIT : And if I try to instanciate this class, I get the following error :
Cannot instantiate interface Laravel\Socialite\Contracts\Factory
How do you make this module to work?
here's how that works in my case
in services.php file
'facebook' => [
'client_id' => '***************',
'client_secret' => '***************',
'redirect' => ""
],
i left redirect empty cause my site is multilingual (so, it fills in a bit later with sessions). if you use only one language, put there your callback absolute path. for example
"http://example.com:8000/my-callback/";
also check your config/app.php. in providers array
Laravel\Socialite\SocialiteServiceProvider::class,
in aliases array
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
my routes look like this
Route::get('facebook', 'Auth\AuthController#redirectToProvider');
Route::get('callback', 'Auth\AuthController#handleProviderCallback');
here's auth controllers methods. put in top
use Socialite;
//იობანი როტ
public function redirectToProvider(Request $request)
{
return Socialite::with('facebook')->redirect();
}
public function handleProviderCallback(Request $request)
{
//here you hadle input user data
$user = Socialite::with('facebook')->user();
}
my facebook app
giga.com:8000 is my localhost (so its the same localhost:8000)
as you can see in Valid OAuth redirect URI, you should put there your callback. in my case i use three urls cause i have three languages. in your case it should be just
http://your-domain-name.com:8000/callback
if you work on localhost, you should name your domain in config/services.php
mine look like this
'domain' => "your-domain.com",
after everything run these commands
php artisan cache:clear
php artisan view:clear
composer dump-autoload
restart your server, clear your browser cookies. hope it helps

Categories