请求缺少必需参数,包括无效参数值,包含多于一次的参数,或者其他方式格式错误

时间:2017-12-21 16:11:17

标签: php laravel laravel-5.3 postman laravel-passport

我正在开发一个带有laravel,护照和邮递员的auth api。我见过相关帖子,但没有一个能解决我的问题。如果我尝试发送请求,则会显示此错误。我已尽力而为但只是显示此错误

/**
 * Gets a connection or waits if one is not available.  A connection is
 * available if one exists that is not being used or if fewer than
 * maxHostConnections have been created in the connectionPool, and fewer
 * than maxTotalConnections have been created in all connectionPools.
 *
 * @param hostConfiguration The host configuration specifying the connection
 *        details.
 * @param timeout the number of milliseconds to wait for a connection, 0 to
 * wait indefinitely
 *
 * @return HttpConnection an available connection
 *
 * @throws HttpException if a connection does not become available in
 * 'timeout' milliseconds
 * 
 * @since 3.0
 */

我对该应用程序的价值是

{
"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"
}

api.php

{
"grant_type" : "password",
"client_id" : "2",
"client_secret" : "fsDFrzGtmpMjoxWtplnvcmgKT3USzKFfKQu6alGF",
"email":"john@gmail.com",
"pssword" : "12345",
"scope" : "*"
}

auth.php

<?php
 use Illuminate\Http\Request;
 Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('signup', 'SignUp@signUp');

user.php的

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],


'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],

AuthServiceProvider.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',
];

请真正感谢任何解决方案

2 个答案:

答案 0 :(得分:0)

您需要'username'字段并在postman参数中传递值 毕竟你的代码绝对正确。没有错误。

答案 1 :(得分:0)

您需要添加refresh_token参数

{
  "grant_type" : "password",
  "refresh_token" : 'your_refresh_token',
  "client_id" : "2",
  "client_secret" : "fsDFrzGtmpMjoxWtplnvcmgKT3USzKFfKQu6alGF",
  "email":"john@gmail.com",
  "pssword" : "12345",
  "scope" : "*"
}

有关更多信息,请参见文档:https://laravel.com/docs/5.8/passport#refreshing-tokens