Open yinkuzej opened 4 years ago
+1
In my case if I change
...
'defaults' => [
'guard' => 'api',
...
to framework's default (as below) it works
...
'defaults' => [
'guard' => 'web',
...
Now I'm testing to look if the changes crash anything
I am creating auth/usermanagement code as Laravel package using Orchestra/TestBench and I get the same error when I run test in the package tree.
Tests run fine when I run them inside a separate Laravel tree (containing my package).
I am creating auth/usermanagement code as Laravel package using Orchestra/TestBench and I get the same error when I run test in the package tree.
Tests run fine when I run them inside a separate Laravel tree (containing my package).
Error when test run inside the package tree.
pf user_can_login_with_valid_credentials PHPUnit 8.4.3 by Sebastian Bergmann and contributors.
Illuminate\Foundation\Testing\TestResponse^ {#1186 +baseResponse: Illuminate\Http\Response^ {#1216 +headers: Symfony\Component\HttpFoundation\ResponseHeaderBag^ {#1217
"no-cache" => true
"private" => true
]
#cookies: []
#headerNames: array:3 [
"cache-control" => "Cache-Control"
"date" => "date"
"content-type" => "Content-Type"
]
#headers: array:3 [
"cache-control" => array:1 [
0 => "no-cache, private"
]
"date" => array:1 [
0 => "Thu, 07 Nov 2019 12:52:02 GMT"
]
"content-type" => array:1 [
0 => "text/html; charset=UTF-8"
]
]
#cacheControl: array:2 [
"no-cache" => true
"private" => true
]
}
#content: """
<!DOCTYPE html>\n
<html lang="en">\n
<head>\n
<meta charset="utf-8">\n
<meta name="viewport" content="width=device-width, initial-scale=1">\n
\n
<title>Server Error</title>\n
\n
<!-- Fonts -->\n
<link rel="dns-prefetch" href="//fonts.gstatic.com">\n
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">\n
\n
<!-- Styles -->\n
<style>\n
html, body {\n
background-color: #fff;\n
color: #636b6f;\n
font-family: 'Nunito', sans-serif;\n
font-weight: 100;\n
height: 100vh;\n
margin: 0;\n
}\n
\n
.full-height {\n
height: 100vh;\n
}\n
\n
.flex-center {\n
align-items: center;\n
display: flex;\n
justify-content: center;\n
}\n
\n
.position-ref {\n
position: relative;\n
}\n
\n
.code {\n
border-right: 2px solid;\n
font-size: 26px;\n
padding: 0 15px 0 15px;\n
text-align: center;\n
}\n
\n
.message {\n
font-size: 18px;\n
text-align: center;\n
}\n
</style>\n
</head>\n
<body>\n
<div class="flex-center position-ref full-height">\n
<div class="code">\n
500 </div>\n
\n
<div class="message" style="padding: 10px;">\n
Server Error </div>\n
</div>\n
</body>\n
</html>\n
"""
#version: "1.1"
#statusCode: 500
#statusText: "Internal Server Error"
#charset: null
+original: """
<!DOCTYPE html>\n
<html lang="en">\n
<head>\n
<meta charset="utf-8">\n
<meta name="viewport" content="width=device-width, initial-scale=1">\n
\n
<title>Server Error</title>\n
\n
<!-- Fonts -->\n
<link rel="dns-prefetch" href="//fonts.gstatic.com">\n
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">\n
\n
<!-- Styles -->\n
<style>\n
html, body {\n
background-color: #fff;\n
color: #636b6f;\n
font-family: 'Nunito', sans-serif;\n
font-weight: 100;\n
height: 100vh;\n
margin: 0;\n
}\n
\n
.full-height {\n
height: 100vh;\n
}\n
\n
.flex-center {\n
align-items: center;\n
display: flex;\n
justify-content: center;\n
}\n
\n
.position-ref {\n
position: relative;\n
}\n
\n
.code {\n
border-right: 2px solid;\n
font-size: 26px;\n
padding: 0 15px 0 15px;\n
text-align: center;\n
}\n
\n
.message {\n
font-size: 18px;\n
text-align: center;\n
}\n
</style>\n
</head>\n
<body>\n
<div class="flex-center position-ref full-height">\n
<div class="code">\n
500 </div>\n
\n
<div class="message" style="padding: 10px;">\n
Server Error </div>\n
</div>\n
</body>\n
</html>\n
"""
+exception: InvalidArgumentException {#1190
#message: "Auth driver [jwt] for guard [api] is not defined."
#code: 0
#file: "./vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php"
#line: 97
trace: {
./vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:97 { …}
./vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:68 { …}
./vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:54 { …}
Illuminate\Auth\AuthManager->Illuminate\Auth\{closure}() {}
./vendor/laravel/framework/src/Illuminate/Auth/AuthServiceProvider.php:84 { …}
Illuminate\Auth\AuthServiceProvider->Illuminate\Auth\{closure}() {}
./vendor/laravel/framework/src/Illuminate/Http/Request.php:517 { …}
./vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php:97 { …}
./vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php:49 { …}
./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 { …}
./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105 { …}
./vendor/laravel/framework/src/Illuminate/Routing/Router.php:682 { …}
./vendor/laravel/framework/src/Illuminate/Routing/Router.php:657 { …}
./vendor/laravel/framework/src/Illuminate/Routing/Router.php:623 { …}
./vendor/laravel/framework/src/Illuminate/Routing/Router.php:612 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176 { …}
./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:130 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 { …}
./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 { …}
./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27 { …}
./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171 { …}
./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:434 { …}
./vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:252 { …}
./tests/Feature/AuthTest.php:29 {
› 'username' => $user->username,
› 'password' => $password,
› ]));
arguments: {
$uri: "http://localhost/auth/login?username=admin&password=secret"
}
}
./vendor/phpunit/phpunit/src/Framework/TestCase.php:1400 { …}
./vendor/phpunit/phpunit/src/Framework/TestCase.php:1020 { …}
./vendor/phpunit/phpunit/src/Framework/TestResult.php:691 { …}
./vendor/phpunit/phpunit/src/Framework/TestCase.php:752 { …}
./vendor/phpunit/phpunit/src/Framework/TestSuite.php:569 { …}
./vendor/phpunit/phpunit/src/Framework/TestSuite.php:569 { …}
./vendor/phpunit/phpunit/src/Framework/TestSuite.php:569 { …}
./vendor/phpunit/phpunit/src/TextUI/TestRunner.php:616 { …}
/home/vishy/.config/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:200 { …}
/home/vishy/.config/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:159 { …}
/home/vishy/.config/composer/vendor/phpunit/phpunit/phpunit:61 { …}
}
}
}
}
I am creating auth/usermanagement code as Laravel package using Orchestra/TestBench and I get the same error when I run test in the package tree.
Tests run fine when I run them inside a separate Laravel tree (containing my package).
When same test run inside Laravel tree instead:
pf user_can_login_with_valid_credentials PHPUnit 8.4.3 by Sebastian Bergmann and contributors.
Illuminate\Foundation\Testing\TestResponse^ {#404 +baseResponse: Illuminate\Http\JsonResponse^ {#1302
#callback: null
#encodingOptions: 0
+headers: Symfony\Component\HttpFoundation\ResponseHeaderBag^ {#1303
#computedCacheControl: array:2 [
"no-cache" => true
"private" => true
]
#cookies: []
#headerNames: array:5 [
"cache-control" => "Cache-Control"
"date" => "Date"
"content-type" => "Content-Type"
"x-ratelimit-limit" => "X-RateLimit-Limit"
"x-ratelimit-remaining" => "X-RateLimit-Remaining"
]
#headers: array:5 [
"cache-control" => array:1 [
0 => "no-cache, private"
]
"date" => array:1 [
0 => "Thu, 07 Nov 2019 12:47:50 GMT"
]
"content-type" => array:1 [
0 => "application/json"
]
"x-ratelimit-limit" => array:1 [
0 => 60
]
"x-ratelimit-remaining" => array:1 [
0 => 59
]
]
#cacheControl: []
}
#content: "{"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTczMTMwODcwLCJleHAiOjE1NzMxNzQwNzAsIm5iZiI6MTU3MzEzMDg3MCwianRpIjoid2hQZlhJOWxLOXdiRkVmNCIsInN1YiI6MSwicHJ2IjoiOTFiNWMwNjAyNTdiYzE3MTE3OGRhZTlhYTY0NjQ2MzA0OGI4YzMwMyJ9.W8JPaIzcIm2Ij_Z7kHvFqa32J4A2yxBU2OGM4LwkVR0","token_type":"bearer","expires_in":43200}"
#version: "1.1"
#statusCode: 200
#statusText: "OK"
#charset: null
+original: array:3 [
"access_token" => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTczMTMwODcwLCJleHAiOjE1NzMxNzQwNzAsIm5iZiI6MTU3MzEzMDg3MCwianRpIjoid2hQZlhJOWxLOXdiRkVmNCIsInN1YiI6MSwicHJ2IjoiOTFiNWMwNjAyNTdiYzE3MTE3OGRhZTlhYTY0NjQ2MzA0OGI4YzMwMyJ9.W8JPaIzcIm2Ij_Z7kHvFqa32J4A2yxBU2OGM4LwkVR0"
"token_type" => "bearer"
"expires_in" => 43200
]
+exception: null
}
}
I encountered the same issue, Basically, this issue is showing because JWT is not compatible with Laravel 6.3 and there is changes in Middlewares' flow of events.
So after tracing the error, I found a temp solution you can use while they are releasing 6.3 compatible release.
The main issue here is in config/auth.php
setting the default guard to api
while its' driver is not defined.
to solve this change as follow:
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'jwt',
...
And refresh your cache php artisan config:cac
This will cause an error in AuthController (as in the documentation) Method Illuminate\Auth\SessionGuard::factory does not exist
, ignore it and complete your controller.
Follow the documentation carefully. then to solve the error, after finishing the controller just use this guard function
public function guard()
{
return Auth::guard('api');
}
Or if you're not following the documentation just use this guard
Auth::guard('api')->attempt([...])
Somehow, the JWT driver is now defined !!
I seem to have this issue as well with laravel/framework
v6.18.13
.
My workaround works like this:
web
default guard in config/auth.php
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
create a new middleware UseApiGuard.php
with this handle
method:
public function handle($request, Closure $next)
{
Auth::shouldUse('api');
return $next($request);
}
api
middleware group in app/Http/Kernel.php
protected $middlewareGroups
= [
...
'api' => [
UseApiGuard::class,
...
]]
use the api
middleware to protect my routes
Route::group([
'middleware' => 'api'], fuction ($router){
...
});
For me this happened after I upgraded to Laravel 7. According to the upgrade guide App\Exceptions\Handler
now uses Throwable
instead of Exception
. If you have traits used in this handler, update those too.
I solved the problem by adding this line to app.php in config folder to the providers: ` 'providers' => [
/*
* Laravel Framework Service Providers...
*/
// ......
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
]
and this is my auth.php content:
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api_customer' => [
'driver' => 'jwt',
'provider' => 'api_customer',
],
// ....
`
Subject of the issue
Describe your issue here.
Your environment
Steps to reproduce
Hello I get this error after upgrading to laravel 6.3
my config/auth.php `<?php
return [
// 'driver' => 'token', 'provider' => 'users', 'hash' => false, ], ],
]; `
my config/jwt.php `<?php
/*
return [
// 'ttl' => env('JWT_TTL', 60), 'ttl' => null,
// 'exp', 'nbf', 'sub', 'jti', ],
];
` Error shown https://i.imgur.com/A2cCf22.png
Actual behaviour
https://i.imgur.com/A2cCf22.png