Missing argument 1 for Illuminate\Auth\AuthManager::createDriver() lumen and JWT - php

I am trying to implement JWT token in my API using Lumen + JWT. I am using this JWT Library, I have set up it, but when I want to validate passed using JWTAuth::attempt($credentials) I get next error
ErrorException in AuthManager.php line 16:
Missing argument 1 for Illuminate\Auth\AuthManager::createDriver(), called in /home/admin/web/mkopilka.ru/public_html/api/referral/vendor/illuminate/support/Manager.php on line 87 and defined
I know where is the problem, but cannot figure out how to solve it because I don't know internals of framework well.
I have question about how does JWT authenticate the user (checks credentials in database, as I can gues it uses model class provided in jwt.php with the following line 'user' => 'App\Models\User'
By default 'user' => 'App\User'
So even if I changed user model in this file I got the next error
vendor/illuminate/auth/EloquentUserProvider.php line 126:
Class '\App\User' not found
I thought and decided to add config/auth.php file with succeeding content
return [
'model' => 'App\Models\User'
];
And now I get the the first exception.
What is wrong I can quess that I have overridden all parameters in auth config file.
Aslo I wonder where can I find (except source code, it will take a lot of time to understand it) explanation how JWTAuth::attempt works ?
Thanks.

Just had same issue myself and stumbled upon this question.
Solution is to add 'driver' => 'eloquent' into your created auth.php file.

I had the same problem on my upgrade from Laravel 4.1 to 4.2 (I think mainly because I updated all the files and tried to make a composer update afterwards).
For me the following worked (like reverting the relevant update steps):
1. Modify auth.php
Add driver, model and table to config/auth.php main array (additionally to the already existing one in the providers sub array):
<?php
return [
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'users',
// ...
2. Add ArtisanServiceProvider
To prevent the error Artisan: Command clear-compiled is not defined readd Illuminate\Foundation\Providers\ArtisanServiceProvider to the service providers
<?php
return [
// ...
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
// ...
3. Update and revert changes
Perform update (composer update) and revert the two previous steps by removing the added lines.

Related

Laravel 5.7 + Spatie Permissions + JWT auth

I'm setting up a REST API using Laravel 5.7. To validate authentication I JWT-auth and for permissions and roles I use Spatie.
My problem: when trying to link a role to a user I get the following error
Spatie \ Permission \ Exceptions \ RoleDoesNotExist
There is no role named admin.
The role do exist in the database:
This is how I'm trying to assign a role to the user:
$user = User::findOrFail(1);
$user->assignRole('admin');
As I'm new to Laravel I'm not sure if it's relevant, but setting the JWT I had to change the driver of the guard in the config/auth.php to jwt
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
I can't see what I'm doing wrong. I added the roles and then tried to add the role to a user.
Check your app namespace. If you updated it from App, be sure to update it in config/auth.php.
On the other hand, if you didn't update the App namespace, try clearing your cache and re-seed the database tables.
php artisan config:cache
php artisan cache:clear
Also check the user model if you have protected $guard_name = 'api'; in there.
Hope this helps. Cheers!
I'm assuming you've manually added the roles to the database. The roles are cached and it causes issues if you don't use the built in create methods.
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
$role = Role::create(['name' => 'writer']);
$permission = Permission::create(['name' => 'edit articles']);
From the GitHub docs
You will need to manually clear the cache with php artisan cache:clear.
The better way to do this is either to use a seeder (for permanent roles) or Tinker to run the code to create roles and permissions, which will trigger the cache to be cleared.
Guard has been changed from the web to api but still try to find web from the database
assign a role like this.
$roleToAssign = Role:: findByName('administrator', 'api');
$user->assignRole($roleToAssign);
#Link
If none of other answers solved your problem
Check that you are using queue
if so
restart the queue

LDAP Auth for Laravel 5.2

I've followed the instructions at https://github.com/strebl/ldap-auth with a brand new laravel project and I can't seem to get it to work. I have done the following:
Added the following line to app.php
Ccovey\LdapAuth\LdapAuthServiceProvider::class
Changed the driver to LDAP in auth.php
'providers' => [
'users' => [
'driver' => 'ldap',
'model' => App\User::class,
]
],
I've also created a adladap.php file that I haven't posted here.
I have also added middleware group in order to make sure the user was authenticated.
Route::group(['middleware' => 'auth'], function () {
Route::get('/test', function(){ return "Test";});
}
However when I try to go to the test route I get the following error
InvalidArgumentException in CreatesUserProviders.php line 40:
Authentication user provider [ldap] is not defined.
I'm sure there's some simple configuration that I've been looking over but for the life of me I can't figure out what it is.
If you are trying to do adminless LDAP, this might be of interest:
laravel-simple-ldap-auth

Laravel 5.1 GuzzleHttp Client error: 404 when using mailgun

I'm using the Mailgun service when sending mail with Laravel. However, i've set this up today and it's just stopped working. I have entered all the correct info in .env, config/services.php and config/mail.php. However i'm still getting the below error:
ClientException in Middleware.php line 69:
Client error: 404
It looks like the domain is not getting passed through somehow, even though in my config/services.php file I have:
'mailgun' => [
'domain' => env('mydomain.com'),
'secret' => env('<my-mailgun-key>'),
],
I have hidden the above credentials for safety, but in my real application they are the proper values.
Please help.
I was having a very similar 404 issue and tried the solution mentioned by Rogério. I thought I was doing it right, but gave it a try anyway. But misuse of the env() function wasn't my problem.
I set the config/services.php back to look like so:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN',''),
'secret' => env('MAILGUN_SECRET',''),
],
This will provide empty strings if the values named MAILGUN_DOMAIN and MAILGUN_SECRET are not found in the .env file. Then, in my .env file, I included the API Base URL and API Key from the Mailgun domain information page. So the .env looked something like this:
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox123abc.mailgun.org
MAILGUN_SECRET=key-123456abcdef
The values were passing along as they should, but still 404. Looking at How do I start sending email documentation at Mailgun, I saw that their API URL included "messages" on the end - which I tried manually adding to the .env setting:
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox123abc.mailgun.org/messages
That didn't work either, but lead me to look more carefully at the stack trace spit out by Laravel. That's when I noticed that the URL it was trying to connect with was:
https://api.mailgun.net/v3https://api.mailgun.net/v3/sandbox123abc.mailgun.org/messages/messages.mime
Ah-ha! Using Mailgun's Base API URL was incorrect! That was made obvious by the repetition of the "https://api.mailgun.net/v3" portion. So the aptly named MAILGUN_DOMAIN setting really just needed to be:
MAILGUN_DOMAIN=sandbox123abc.mailgun.org
Seems obvious now, but I spent way too much time figuring it out. Thought I'd put it out there in case anyone else happened to miss that detail
I hade the same problem as you and solved it by removing the env() call.
Thats because env will return the value of the env variable in the first argument (not the value of the argument) and otherwise return the second argument.
So:
'mailgun' => [
'domain' => 'mydomain.com',
'secret' => '<my-mailgun-key>',
],
Try that.

Unable to generate a Cashier PDF in Laravel

I am using Laravel 5 to generate a PDF from a subscription generated from Cashier. The docs say this is as simple as calling:
return $user->downloadInvoice($invoice->id, [
'vendor' => 'Your Company',
'product' => 'Your Product',
]);
Unfortunately I'm getting an odd error:
No hint path defined for [cashier]
The code I am actually using is as follows:
Route::get('billing/invoices/download/{id}', function($id){
$user = Auth::user();
//$invoice = $user->invoices()->find($id);
return $user->downloadInvoice($id, [
'vendor' => 'Certify Me',
//'product' => $invoice->lines->data[0]['plan']->name,
'product' => 'Subscription',
]);
});
The docs make me assume that the PDF is automatically generated. I'd then assume I could override the PDF layout if I chose to.
I just ran into this (L5.1, Cashier 6.0). This seems to be caused by the service provider not being correctly loaded.
Here is how I fixed it:
Check that you have added the correct service provider, at the time of writing that is Laravel\Cashier\CashierServiceProvider to your config/app.php
If it still doesn't work, go run php artisan config:clear to make sure that the service provider is picked up.
Happy invoicing!
I'm going to resurrect this beast.
I had a similar issue because the service provider was not loaded. If you checkout CashierServiceProvider you'll see it adds the necessary 'namespace' for the 'cashier' prefixed views.
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'cashier');
$this->publishes([
__DIR__.'/../../views' => base_path('resources/views/vendor/cashier'),
]);
}
Add Laravel\Cashier\CashierServiceProvider to your config/app.php file and inside the providers key.
For anyone who runs across this like we did.

Testing Yii REST application using a second database

I wrote an API using Yii2 and following the REST guide. My API is working and I want to write some tests for it, so I once again followed the guide on how to run tests and got unit tests working. I then looked around Codeception documentation about testing WebServices and got this working too.
My problem is that API calls are not using my test database. I have two databases, one called db and the other testdb. Here is my config.php file in tests/codeception/config/:
return [
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;port=8889;dbname=testdb;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',
],
'mailer' => [
'useFileTransport' => true,
],
'urlManager' => [
'showScriptName' => true,
],
],
];
I wrote a simple test that send a GET request to an endpoint to retrieve data. My test database is empty so I am expecting to receive an empty response, but I get the content of my other database instead.
I then tried to set YII_ENV to test as described in the Environment Constant section here so that I could test against the env variable YII_ENV_TEST and change the db configuration accordingly. I tried to set this variable in the _bootstrap.php file in the tests/codeception/ folder:
defined('YII_ENV') or define('YII_ENV', 'test');
I then logged the value of YII_ENV in the web/index.php file (index-test.php is not called, might be a problem too), and it is undefined.
What am I doing wrong? I tried including the Yii2 module in my api.suite.yml file but requests don't have return code anymore if I do that, it returns N/A. Is there another way to change which database Yii should use?
You can make an test_config.php file and at the end of the config place this
if (file_exists('protected/config/test_config.php'))
{
include 'test_config.php';
}
the file will be included if it exists. And the file test_config.php should contain the overwritten value for the db connection.
Hope this helps!
Keep on coding!
Ares.
Well I found a "solution" by using this other app template: https://github.com/githubjeka/yii2-rest
The file organization fits my needs better and I can easily configure which database to use.

Categories