【问题标题】:Unable to fetch refresh token无法获取刷新令牌
【发布时间】:2022-12-14 09:48:11
【问题描述】:

我正在尝试从 url oauth/token 获取令牌详细信息(包括刷新令牌和过期时间),但不幸的是我无法通过直接调用该函数的 Postman 获取它。但是如果我直接调用 URL 那么它将完美地工作。 下面提供了我的代码详细信息

1.控制器登录功能

 $response = Http::asForm()->post('http://127.0.0.1:9394/oauth/token', [
                'grant_type' => 'password',
                'client_id' => '3',
                'client_secret' => 'V7GUakzjRViTnIP6zryDymYv5tD0dpLxGvhm0gUq',
                'username' => $request->email,
                'password' => $request->password,
                'scope' => '',
            ]);

2.Postman调用登录功能enter image description here

3.邮递员直接调用urlenter image description here

我的目标是在人们登录的同时获取令牌详细信息,因为 Passport 仅显示使用创建令牌生成令牌的函数。

【问题讨论】:

  • 对于刷新令牌,需要发送文档中给出的令牌laravel.com/docs/9.x/passport#refreshing-tokens
  • @ABHILASHAK.M 您提供的方法在 Postman 中有效(直接调用 oauth/token URL),但我尝试使用 Postman 在 Laravel 中调用此函数仍然出现与密码 grand_type 相同的错误。你有什么想法吗?

标签: laravel postman laravel-passport


【解决方案1】:

我可以通过使用以下代码调用 Passport Oauth/token URI 来解决我的问题,下面提供了我的代码。

$request = Request::create('oauth/token', 'POST', [
    "grant_type"=> "password",
    "client_id"=> "3",
    "client_secret"=> "V7GUakzjRViTnIP6zryDymYv5tD0dpLxGvhm0gUq",
    "username"=> "kanasai1@gmail.com",
    "password"=> "12345678",
    "scope"=> ""
]);

$result = app()->handle($request);

// Capture
$token = json_decode($result->getContent());

非常感谢https://stackoverflow.com/a/56886318/20642827

【讨论】:

  • 请标记为正确或接近。请注意,不推荐使用 grant_type 密码(Legacy Grants)。 here查看更多。
猜你喜欢
  • 2019-10-26
  • 1970-01-01
  • 2021-06-12
  • 2013-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-05
相关资源
最近更新 更多