【问题标题】:The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed请求缺少必需的参数、包含无效的参数值、包含不止一次的参数或格式错误
【发布时间】:2018-06-04 08:28:41
【问题描述】:

我正在开发一个带有 laravel、passport 和 postman 的 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"
}

我对应用程序的价值是

{
"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,
    ],

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

任何解决方案将不胜感激

【问题讨论】:

  • 您收到了"Check the username parameter" 的提示,但我在您发布的代码中没有看到username;是否应该在您的有效负载数据中将email 替换为username?此外,您还有pssword,这是password 的拼写错误。
  • 谢谢我用电子邮件代替用户名
  • 你在哪里告诉护照你想使用email而不是username? Passport 使用电子邮件地址,但 OAUTH 使用用户名 laravel.com/docs/5.5/passport#password-grant-tokens

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


【解决方案1】:

您需要“用户名”字段并在邮递员参数中传递值 毕竟你的代码是绝对正确的。没有错误。

【讨论】:

  • 是的,我在邮递员中将email 参数替换为username 并且它有效!
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    • 2021-08-07
    • 1970-01-01
    相关资源
    最近更新 更多