请求缺少必需参数、包含无效参数值、多次包含参数或格式错误

The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed

我正在用laravel、护照和post人开发一个授权api。我看过相关的 post 但其中 none 解决了我的问题。如果我尝试发送请求,它会显示此错误。我已尽我所能,但它只是显示此错误

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

我的应用价值是

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

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

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

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();
    }
}

请提供任何解决方案,我们将不胜感激

您需要 'username' 字段并在邮递员参数中传递值 毕竟你的代码绝对是 right.nothing 错误。

您需要添加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