Driver [provider] not supported laravel/socialite - laravel

I'm using Laravel 5.4 and Socialite 3.0
With every new socialite provider I add I get the error:
Driver [provider] not supported.
for example when adding socialiteproviders/twitch 3.0 I will get the error:
Driver [twitch] not supported.
However I can use a provider that's already built in to Socialite, github for example works as expected.
I have tried three different providers and I get the same result each time, what am I doing wrong?
Here are my routes:
Route::get('/auth/bnet', 'BnetController#redirectToProvider');
Route::get('/auth/bnet/return', function() {
$user = Socialite::driver('battlenet')->user();
dd($user->accessTokenResponseBody);
});
Route::get('/auth/git', function() {
return Socialite::driver('github')->redirect();
});
Route::get('/auth/twitch', function() {
return Socialite::with('twitch')->redirect();
});
Here's my $listen from my EventServiceProvider:
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// add your listeners (aka providers) here
//'SocialiteProviders\Battlenet\BattlenetExtendSocialite#handle',
'Reflex\SocialiteProviders\BattleNet\BattleNetExtendSocialite#handle',
'SocialiteProviders\Twitch\TwitchExtendSocialite#handle',
],
];
I have added SocialiteProviders\Manager\ServiceProvider::class, to my providers array in app.php, I have added the Socialite facade ('Socialite' => Laravel\Socialite\Facades\Socialite::class,) to my aliases array also in app.php and have added the appropriate keys to my .env

I had the same issue and I found solution.
In config/app.php providers array:
'providers' => [
// ...
Laravel\Socialite\SocialiteServiceProvider::class,
\SocialiteProviders\Manager\ServiceProvider::class,
// ...
]
In app/Providers/EventServiceProvider.php:
protected $listen = [
// ...
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
'SocialiteProviders\VKontakte\VKontakteExtendSocialite#handle',
],
]
You missed \ at start of 'SocialiteProviders\Twitch\TwitchExtendSocialite#handle'.

Hopefully this helps someone, but I found that I had to separate the EventServiceProvider.php listen classes with "\\" instead of "\". Laravel 5.6. e.g:
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
'SocialiteProviders\\Twitch\\TwitchExtendSocialite#handle',
'SocialiteProviders\\Podio\\PodioExtendSocialite#handle',
],
If you're still struggling, triple-check to ensure all of the packages are installed.
I also found that including...
Laravel\Socialite\SocialiteServiceProvider::class,
...in your config/app.php is not necessary when using SocialiteProviders\Manager.

Make sure that you have updated config/services.php to include the client_id client_secret and redirect from your provider.
Clear your config and try again.

Adding an answer here because this question comes up while searching for the same error as it pertains to Lumen as well and I suspect others may run into the same issue that I did.
The Lumen-specific documentation for additional providers doesn't appear to mention some gotchas (at least, for my version of Lumen) and Lumen needs a little extra configuration to work compared to Laravel.
I'm on Lumen 5.8.2 and had been becoming increasingly frustrated getting Socialite with additional providers set up - all of my configuration in bootstrap/app.php and EventServiceProvider.php seemed correct (and was) until I realized that Lumen wasn't actually registering the EventServiceProvider itself.
To remedy this problem, register the EventServiceProvider within your bootstrap/app.php setup:
$app->register(App\Providers\EventServiceProvider::class);
With the EventServiceProvider registered, just refer to the other answers here to configure events, the provider's service config and registering Socialite in app.php and you ought to be good to go.

I had the same issue, to solve it i change the order of my bootstrap/app.php config, try moving the next lines after the Event ServiceProvider:
$app->register(\SocialiteProviders\Manager\ServiceProvider::class);
class_alias(Laravel\Socialite\Facades\Socialite::class, 'Socialite');
//$app->register(Laravel\Socialite\SocialiteServiceProvider::class);
After:
$app->register(App\Providers\EventServiceProvider::class);
My issue was because i declared all the Socialite and SocialiteProvider stuff before.

Related

activate some fortify pages for production and others for testing

i have a version of laravel 8x jetstream with fortify on a test server and a production server.
test: prj_l8xtest.com
production: prj_l8xprod.com
I wanted to activate or deactivate some pages made available by fortify, they can be activated or deactivated from here -> prj_l8xlocal/config/fortify.php:
.
.
.
.
'features' => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
'confirmPassword' => true,
]),
],
I would like to activate or deactivate some of these pages depending on test or production.
i think i could do it all with an if(){} which checks url in question (production or test), but i would have no idea how to take url. Or are there better solutions than my proposal?
The config file is normal PHP so you can write a normal PHP script in it and then return the result if you want. However the problem is that the request information is not loaded when the config is first read which is why I recommended a service provider to modify the config values in the boot method. You can try adding the following in your AppServiceProvider in the boot method:
public function boot() {
// other boot code
if (app()->environment('production')) {
config([ 'fortify.features' => array_merge(config('fortify.features'), [
// production only features
]);
}
}
Be aware that not all the request information might be available at this point so you may need to directly access $_SERVER variables to find what you need.

route model binding doesn't work anymore with api package devolpment in in Laravel 8.x

I created an api which is delivered with package development composer. in Laravel 7 it was possible to add the route model binding with:
Route::group(['namespace' => 'Acme\Package\app\Http\Controllers\Api'], function () {
// fomer possibility:
Route::apiResource('api/comments/', 'CommentController')->middleware('bindings');});
In Laravel 8 that's not possible anymore. I've tried almost everything the last days, but either the route-model-binding is not working, or the class can't be found:
Target class [bindings] does not exist.
I really hope someone can post an answer to the problem, or a hint or anything useful.
many thanks in advance
EDIT:
Thanks for the answers, including the middleware in the Route::group like mentioned:
Route::group(['namespace' => 'Acme\Package\app\Http\Controllers\Api', 'middleware' => 'Illuminate\Routing\Middleware\SubstituteBindings']
did it.
In Laravel 8 the alias for this middleware has been removed. You can either use it by its full class name
Illuminate\Routing\Middleware\SubstituteBindings
or add the alias back in to your app/Http/Kernels.php in $routeMiddleware as follows:
protected $routeMiddleware = [
'auth' => Authenticate::class,
'bindings' => Illuminate\Routing\Middleware\SubstituteBindings,
/*...*/
You have to be careful if you are relying on values in someones application to exist. I could use a different name/alias for that middleware if I wanted to in my HTTP Kernel. You should be using the FQCN for that middleware that comes from the framework when referencing it like that.
In a default Laravel 8 install there is no middleware named/aliased as 'bindings'. It is referenced by its FQCN, Illuminate\Routing\Middleware\SubstituteBindings, which is how you should probably be referencing it from a package.
You can provide a config file for someone to alter these things if you would like. Then you can use your configuration to know which middleware to reference.

Integrate CHARGEBEE library to LARAVEL

Im starting using LARAVEL last version 7.12 and I'm having an issue trying to integrate CHARGEBEE library to make request to Chargebee api.
I was reading that I can install packages with composer, I did it:
composer require chargebee/chargebee-php:'>=2, <3'
Doing that now I have downloaded chargebee lib here: /vendor/chargebee/chargebee-php/
Now also I saw This stack overflow question here:
That for the user to correctly use this Library-Package I need to create a ServiceProvider so I did:
php artisan make:provider ChargeBeeServiceProvider
then I really don't know how to write the REGISTER() function here, I added also this line: App\Providers\ChargebeeServiceProvider::class, to /config/app.php to 'providers'
ChargebeeServiceProvider
Right now I have a controller: /app/http/controllers/PortalController and I'm trying to use this:
ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = ChargeBee_Customer::all(array( "firstName[is]" => "John",
"lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
foreach($all as $entry){
$customer = $entry->customer();
$card = $entry->card();
}
PortalController
BUT on the frontend it's giving me an error:
Error Class 'App\Http\Controllers\ChargeBee_Customer' not found
Not really sure how i can use this custom Chargebee library here on Laravel.
can somebody please help to integrate in the correct way ?
Thanks!
The real problem here is that ChargeBee_Environment class doesn't exists.
It should be Chargebee\ChargeBee\Environment. And the Models are in their own folder, for example the Portal is ChargeBee\ChargeBee\Models\PortalSession
WPTC-Troop's answer provides some great information on the issue of using a service provider vs library directly, but in the end you need to call the correct classes.
My working code for creating a portal session is below. It would be similar for a Customer object:
\ChargeBee\ChargeBee\Environment::configure("test-site","test_api_key");
$result = \ChargeBee\ChargeBee\Models\PortalSession::create(["customer" => ["id" => "AzZlwTSSVw9871E9g"]]);
$portalSession = $result->portalSession();
$output = $portalSession->getValues();
return $output;
Two things, you can use any third party library as Service Provider(DI) in Laravel or use it directly where ever you needed(mostly in controller)
Not just third party library you can ease the instance creation of class etc in Service Provider. Basically it's for dependency injection, Check IoC in general you'll understand it better.
You tried/mixed both in your case and didn't completely use any single approach.
You've created a Service Provider called ChargeBeeServiceProvider but it doesn't return/bind any resource or no API initialization done in register method. This is where you register and make use of DI. You can bind in properties as well. Here is the official doc to it.
You tried to use directly by initializing ChargeBee_Environment and use ChargeBee_Customer but you didn't mention where to look for this class that is the reason you get the error(Error Class 'App\Http\Controllers\ChargeBee_Customer' not found). I mean compiler will look for ChargeBee_Environment from the same local space but ChargeBee_Environment is available from global scope.
Simple solution to your same code. Add \ to the class to look from global scope or make use of use statement in the top of your file similar to import in java but still we need to require/include the file in php but don't worry, chargebee make use of autoloader(Check here -> composer.json) so it will be loaded automatically in both approach.
\ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = \ChargeBee_Customer::all(array( "firstName[is]" => "John",
"lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
Try the above and let me know. Answered from mobile device. Code is not tested fully(Just copied your and added \ to it).
Excuse brevity :)
I have a solution to use ChargeBee and Laravel. Don't need any: register provider, add to aliases or add path to autoload in composer.json by file path. Just add in use classes that you need in code your Service or your Controller. Like use ChargeBee_Environment and other.
use ChargeBee_Environment;
use ChargeBee_Customer;
ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = ChargeBee_Customer::all(array( "firstName[is]" => "John", "lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
foreach($all as $entry){
$customer = $entry->customer();
$card = $entry->card();
}

Enabling session in lumen framework

I have two (but let's image more) micro-services (API) which need to be aware of authenticated user. Ideally I would simple like to resume their sessions.
All micro-services are using same storage for sessions: redis.
All API calls will have Cookie header, so all services will be able to resume sessions based on that cookie. I have successfully implemented this via PHP $_SESSIONs.
Now the question: how would you go about implementing this with Laravel/Lumen?
Last update on 5th of March 2021
(This answer was getting a lot of attention from Laravel community so I thought of updating it.)
Laravel has officially stopped supporting sessions & views in laravel/lumen framework from version 5.2 and on wards.
But laravel still have a component illuminate/session which can be installed in lumen/framework and we can play around with this.
Step - 1
install illuminate/session using
composer require illuminate/session
Step - 2
Now goto bootstrap/app.php and add this middleware
$app->middleware([
\Illuminate\Session\Middleware\StartSession::class,
]);
Purpose of adding the above middleware is to start session on every request and save session before serving response.
Step - 3
Now add config/session.php, since it is not present in Lumen by default. You can take session.php from Laravel official repo.
Step - 4
Create framework session storage directory by
mkdir -p storage/framework/sessions
Thanks to DayDream
Step - 5
In bootstrap/app.php add bindings for \Illuminate\Session\SessionManager
$app->singleton(Illuminate\Session\SessionManager::class, function () use ($app) {
return $app->loadComponent('session', Illuminate\Session\SessionServiceProvider::class, 'session');
});
$app->singleton('session.store', function () use ($app) {
return $app->loadComponent('session', Illuminate\Session\SessionServiceProvider::class, 'session.store');
});
Thanks to #xxRockOnxx for finding loadComponent method.
It takes 3 arguments,
first one is config file name. (file should be present in config/ directory)
second is ServiceProvider FQN
third is return of this method.
loadComponent just calls the $app->register and inject $app while building the ServiceProvider
How to Use
// Save Session
$router->get('/', function (\Illuminate\Http\Request $request) {
$request->session()->put('name', 'Lumen-Session');
return response()->json([
'session.name' => $request->session()->get('name')
]);
});
// Test session
$router->get('/session', function (\Illuminate\Http\Request $request) {
return response()->json([
'session.name' => $request->session()->get('name'),
]);
});
I've also added example over github supporting from lumen framework v5.6 to all the way to current version v8.0.
https://github.com/rummykhan/lumen-session-example
It is important to that you also use $request->session(), otherwise it will not work.
I tried the solution mentioned above, however, it's also required to create a folder storage/framework/sessions if using the default settings.
The accepted answer is outdated.
I answered and explained a bit how to properly do it in my answer on this question
I also posted what is the problem on my question at Laracasts
To quote:
the solution that is found in the link you gave is that, first it tells you to manually register the SessionManager to prevent the unresolvable depedency parameter #0 $app then also register the existing SessionServiceProvider which also binds another instance SessionManager.
Problem with that is, some components use the other instance and other parts use the new one which causes my auth attempt session not being save despite actually being put inside.

Laravel getting Class Broadcast not found after upgrade from 5.3 to 5.4

I keep getting class Broadcast not found in Laravel 5.4 when I reload my project after I upgraded from 5.3.
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Broadcast' not found
Just ran in to the same issue. Most likely this you need to add the Broadcast alias to your config/app.php file
'aliases' => [
'Broadcast' => Illuminate\Support\Facades\Broadcast::class
]
For some reason the Broadcast facade isn't making it through from the BroadcastServiceProvider.php to your auth listings in channels.php. The quick easy fix is to directly require the Broadcast facade in your channels.php file:
<?php
use Illuminate\Support\Facades\Broadcast;
/*
All of your broadcast auth stuff here
*/

Resources