【问题标题】:"error": "invalid_grant" Laravel 7 Passport“错误”:“invalid_grant” Laravel 7 护照
【发布时间】:2020-05-25 10:03:53
【问题描述】:

我将 Laravel 7 与护照一起使用,但出现了一些错误

这是我的控制器

class LoginController extends Controller
{
    public function login(Request $request)
    {
        $response = Http::post(
            'http://localhost/vue-spa/public/oauth/token',
            [
                'grant_type'    => 'password',
                'client_id'     => 2,
                'client_secret' => 'Z7YFRiUQITRGkWAgCuI8rNyss7BVQJDQXMZrRWiR',
                'username'      => $request->email,
                'password'      => $request->password,
                'scope'         => '',
            ]
        );

        if ($response->clientError()) {
            return $response->json('Email atau Password Salah', 400);
        } elseif ($response->serverError()) {
            return $response->json('Server Error', 500);
        }

        return $response->body();
    }
}

我得到这样的错误

我必须解决这个问题

只需替换

'grant_type' => 'password'

'grant_type' => 'client_credentials'

【问题讨论】:

标签: laravel laravel-passport laravel-7


【解决方案1】:

我必须解决这个问题

只需替换

'grant_type' => 'password'

'grant_type' => 'client_credentials'

【讨论】:

  • 这个答案实际上是不正确的,因为请求会忽略用户名和密码字段,并仅根据 client_id 和 client_secret 为您提供身份验证令牌。这是与您尝试的身份验证不同类型的身份验证。
猜你喜欢
  • 2018-09-26
  • 1970-01-01
  • 2020-11-12
  • 2018-02-19
  • 2021-02-05
  • 2018-05-15
  • 2018-12-20
  • 1970-01-01
  • 2019-02-10
相关资源
最近更新 更多