overtrue / socialite

Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.
MIT License
1.3k stars 241 forks source link

gitee获取用户信息报错 #275

Closed yangwenqian closed 5 months ago

yangwenqian commented 5 months ago
$socialite = new SocialiteManager(config('socialite'));
$oauth = $socialite->create('gitee');
if (!Request::has('code')) {
      $url = $oauth->redirect(Request::fullUrl());
      return redirect($url);
}
$user = $oauth->userFromCode(Request::input('code'));

提示:

production.ERROR: Client error: `POST https://gitee.com/oauth/token` resulted in a `401 Unauthorized` response:
{"error":"invalid_request","error_description":"这个请求缺少必要的参数,或者参数值、格式不正确"}
 {"exception":"[object] (GuzzleHttp\\Exception\\ClientException(code: 401): Client error: `POST https://gitee.com/oauth/token` resulted in a `401 Unauthorized` response:
{\"error\":\"invalid_request\",\"error_description\":\"这个请求缺少必要的参数,或者参数值、格式不正确\"}
yangwenqian commented 5 months ago

找到原因了,gitee在userFromCode时还需要传一次redirect_uri,所以要么在config里配置redirect参数,要么

$user = $oauth->withRedirectUrl(Request::url())->userFromCode(Request::input('code'));