I have an issue with Socialite on Laravel 5.5 I have Socialite required by composer, updated services.php with different providers credential and updated providers in app.php This is the error I am getting
Type error: Argument 1 passed to Laravel\Socialite\SocialiteManager::formatRedirectUrl() must be of the type array, null given
Any help is highly appreciated.
In most of the cases, the issue is solved through 3 steps:
Run php artisan clear-compiled
Run composer dump-autoload
Run php artisan optimize
Hope it helps. Thanks.
Check config/services.php for the provider you're authenticating with. The redirect entry needs to be set to your defined route.
'redirect' => 'http://your-callback-url'
Example:
// config.services.php
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect' => 'http://example.com/github/redirect',
],
// routes/web.php
Route::get('github/redirect', 'GitHubController#redirect')
Related
I've seen many posts about this error, but none of the solutions are working for me.
I'm running Laravel with Passport which is working fine on my development server. As expected, when attempting to check if a user is authenticated on my development server, it returns the catch (inside an axios call):
Development Server
"message":"Unauthenticated."
However, when running the same code on my production server, it returns the catch:
Production Server:
"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token'
in 'where clause' (SQL: select * from `users` where `api_token` = ...
I have have run Passport migration and ['guards']['api']['driver'] set to passport in config/auth.php, and updated the configuration cache that apparently solved the problem for others.
It looks like authentication needs to use the oauth tables from passport migration, but the query appears to be looking at the user table.
EDIT:
I was able to determine that my development server uses the RequestGuard class to find user and my production server uses the TokenGuard class to find user.
I have faced the same problem. And I am using Laravel Passport. It all about configuration. got to config/auth.php and change driver name of api array to passport within the guards array
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',//instead of token
'provider' => 'users',
'hash' => false,
],
],
I was facing same problem and i have solve this by
php artisan config:clear
php artisan config:cache
php artisan cache:clear
may be it helpful
it also may happen when you use wrong auth middleware :
public function __construct()
{
$this->middleware('auth:api');
}
for example for using sanctum :
public function __construct()
{
$this->middleware('auth:sanctum');
}
Despite the confusing error, I followed the steps in this post and it correctly now routes the auth request through the RequestGuard and authentication is made as expected.
Not sure how cache can get messed up to cause this, but I'm guessing that my config cache was stuck on web guard and perhaps clearing it now routes correctly through the api guard.
Hope this helps others.
there must be a column named api_token in your users table ,
and this column must be filled with unique values for each record ,
you can add it to your migration like
$table->string(‘api_token’, length)->after( .. ) or create manually
api apps authanticates the users via using the api_token value , instead "id"
I know the question got answered, but this answer is explained to those who really want to know the real cause of the error in depth.
Remember, it is an error when your route in the API is a protected route and you need to specify a token as a bearer while sending a request after authentication to the protected routes.
The below route is protected, if I want to request it I will need an access token that is generated with authentication through the passport.
Route::middleware('auth:api')->group(function () {
Route::get('/loginCheck', 'Auth\ApiAuthController#LoginCheck');
});
What you need to do is when you change the "token" to "passport" are as follows:
Location of below file: config\auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',//instead of token
'provider' => 'users',
'hash' => false,
],
],
then you will need to run the following commands.
php artisan cache:clear
php artisan route:clear
php artisan config:cache
now start the laravel server again
php artisan serve
And you are done!
Try running:
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I have been solved it by running the following commands in the composer window
php artisan key:generate
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I'm trying to install Sentry Error Tracking into my Laravel 5 Project. It throws an Error when i try publishing the Provider using the command
php artisan vendor:publish --provider="Sentry\SentryLaravel\SentryLaravelServiceProvider"
I added this into config/app.php
'providers' => array(
// ...
Sentry\SentryLaravel\SentryLaravelServiceProvider::class,
)
'aliases' => array(
// ...
'Sentry' => Sentry\SentryLaravel\SentryFacade::class,
)
Then i ran
php artisan vendor:publish --provider="Sentry\SentryLaravel\SentryLaravelServiceProvider"
And it threw the Error
In ProviderRepository.php line 208:
Class 'Sentry\SentryLaravel\SentryLaravelServiceProvider' not found
I've been searching for various solutions but none of them worked for me. This is very important for my project. Can i please please get some assistance. Thank You.
I recommend official sentry documentation.
https://sentry.io/for/laravel/
Not sure what is your exact development environment.(OS, PHP version, laravel version etc).
Here are something you can check.
check your installed sentry laravel package. If you did not install it, use next command to install.
composer require sentry/sentry-laravel
check version of sentry/sentry-laravel from composer.json.
Please notice after version 1.x namespace has been changed to
'providers' => array(
Sentry\Laravel\ServiceProvider::class,
)
'aliases' => array(
'Sentry' => Sentry\Laravel\Facade::class,
)
Namespace update
version 0.x
Sentry\SentryLaravel\SentryLaravelServiceProvider::class
https://github.com/getsentry/sentry-laravel/blob/0.10.1/src/Sentry/SentryLaravel/SentryLaravelServiceProvider.php
version 1.x
Sentry\Laravel\ServiceProvider::class
https://github.com/getsentry/sentry-laravel/blob/1.0.0/src/Sentry/Laravel/ServiceProvider.php
This is a fresh copy of Laravel 5.6.
using spatie laravel permissions.
I have maybe altered something while dealing with permissions that could have altered the guard. I have no idea what since I can't see any git changes, maybe via the DB?
At first I tried to tinker and give a specific user admin privileges with:
$role = Spatie\Permission\Models\Role::where('name', 'admin')->get()->first();
When that returned undefined, I checked Auth::guard('admin'), that returns undefined, so I understand that the issue has nothing to do with Spatie package.
After looking in a few questions/answers here on stackoverflow, one of them being config:clear and config:cache, which didn't work and still getting undefined for Auth guard admin.
Any other options I could take to get Auth admin?
thanks
In case you edited your config/auth.php, e.g. to add another guard and your config is cached, your guards may not be reloaded. If you experience this problem, clearing the config will fix it.
https://github.com/laravel/laravel/blob/v5.2.0/config/auth.php
php artisan config:clear OR php artisan config:cache
I'm using Laravel 5.4.
Add admin or administrator to the auth guards. After this php artisan config:clear can be run to remove the previous cached configurations. It should match your roles->name in the database.
\config\auth.php (file)
'guards' => [
...
'administrator' => [
'driver' => 'session',
'provider' => 'users',
],
],
An old question, but stil valid from Laravel 5 to 7
When I try to login with google using the Laravel Socialite package, it
returns an error saying missing required paramater Client_ID. I have
defined the id in my .env file and called it here in my services.php file. Not sure why this error is happening. Any assistance with this would be greatly appreciated. Thank you.
My services.php file:
'google' => [
'client_id' => env('GOOGLE_ID'),
'client_secret' => env('GOOGLE_SECRET'),
'redirect' => env('GOOGLE_URL'),
],
My .env file:
GOOGLE_ID=xxxxxxxxxx
GOOGLE_SECRET=xxxxx
GOOGLE_URL=URL/login/google/callback
Using composer, I have installed Socialite package to my local machine. It works well. Then I upload all the vendor/laravel/socialite directory as it is to server. Then on server, in composer.json added the line -
"laravel/socialite": "^2.0"
Also, in config/app.php make below changes -
In provider section add the line -
Laravel\Socialite\SocialiteServiceProvider::class,
In aliases section add this line -
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
Then, as per documentation add below code in config/services.php file -
'facebook' => [
'client_id' => '{{my_client_id}}',
'client_secret' => '{{my_secret_key}}',
'redirect' => 'http://mydomain/public/callback',
],
The Controller, I am using has included use Socialite; at top.
Bur now, it gives me error as Class 'Socialite' not found on server. Where as it works fine on my local machine.
Am I missing something to upload on server?
Your help is appreciated.
Thanks.
You need to do dump autoload everytime you make changes in composer.json, composer dump-auto