laravel 请求缺少必需的参数、包含无效的参数值、包含多个参数或其他格式错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47928728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed
提问by oshabz
I am developing an auth api with laravel, passport and postman. I have seen related post but none of them solved my problem. If I try to send a request it shows me this error. I have tried all I can but it just displays this error
我正在开发一个带有 Laravel、护照和邮递员的 auth api。我看过相关的帖子,但没有一个能解决我的问题。如果我尝试发送请求,它会显示此错误。我已经尽我所能,但它只显示这个错误
{
"error": "invalid_request",
"message": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.",
"hint": "Check the `username` parameter"
}
my value for the application is
我对应用程序的价值是
{
"grant_type" : "password",
"client_id" : "2",
"client_secret" : "fsDFrzGtmpMjoxWtplnvcmgKT3USzKFfKQu6alGF",
"email":"[email protected]",
"pssword" : "12345",
"scope" : "*"
}
api.php
api.php
<?php
use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('signup', 'SignUp@signUp');
auth.php
身份验证文件
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
User.php
用户名.php
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','vCode',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
AuthServiceProvider.php
AuthServiceProvider.php
namespace App\Providers;
use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
Passport::routes();
}
}
Please any solution will be really appreciated
请任何解决方案将不胜感激
回答by pratik prajapati
you required 'username' field and passing value in postman parameter After all your code is absolutly right.nothing error.
您需要“用户名”字段并在邮递员参数中传递值 毕竟您的代码绝对正确。没有任何错误。
回答by Arish Rehman Khan
You need to add refresh_token
parameter
您需要添加refresh_token
参数
{
"grant_type" : "password",
"refresh_token" : 'your_refresh_token',
"client_id" : "2",
"client_secret" : "fsDFrzGtmpMjoxWtplnvcmgKT3USzKFfKQu6alGF",
"email":"[email protected]",
"pssword" : "12345",
"scope" : "*"
}
See the documentation for more information : https://laravel.com/docs/5.8/passport#refreshing-tokens
有关更多信息,请参阅文档:https: //laravel.com/docs/5.8/passport#refreshing-tokens