【问题标题】:Use Laravel Socialite user returns missing authorization_code使用 Laravel Socialite 用户返回缺少的授权码
【发布时间】:2021-03-01 17:38:45
【问题描述】:

我正在使用 Laravel Socialite 通过 SuperOffice API 登录。刚刚将提供程序添加为pr,但已经对其进行了测试。我在本地使用提供程序superoffice,并在我正在创建的包superoffice-api 内使用。已将这两个包添加到 Laravel 应用中的 composer.json:

"repositories": [
     {
         "type": "path",
         "url": "./packages/superoffice-api"
     },
     {
        "type": "path",
        "url": "./packages/superoffice"
     }
]

还以同样的方式在superoffice-apicomposer.json 中添加了superoffice Socialite 提供程序。

登录过程正常,但在尝试使用用户进行其他 API 调用时出现问题。我的意思是在回调中我可以执行以下操作:

public function superofficeCallback(Request $request): RedirectResponse
{
     $user = Socialite::driver('superoffice')->stateless()->user();

     return redirect()->route('dashboard.index')->with([
         'message' => 'Loggedin with SuperOffice as '.$user->name,
         'success' => true,
      ]);
}

这会按预期显示$user->name。现在,当尝试在 superoffice-api 包中调用 Socialite::driver('superoffice')->stateless()->user() 时,我收到以下错误消息:

GuzzleHttp\Exception\ClientException:客户端错误:POST https://sod.superoffice.com/login/common/oauth/tokens 导致 400 Bad Request 响应: { "error": "invalid_request", "error_description": "缺少授权码"}

不管是在方法中调用还是在类的__construct()中调用。

所以我的问题是如何在包superoffice-api 中使用社交名流提供者superoffice 用户?这是获取access_token 所必需的。可以想象,因为 Socialite 在包中被调用,所以缺少某种引用。

【问题讨论】:

    标签: laravel laravel-socialite superoffice-api


    【解决方案1】:

    这里的问题是access_tokenrefresh_token 需要以其他方式存储在回调函数中。例如,当存储在数据库中时,您可以在任何地方使用令牌。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多