我有一个奇怪的问题,使用Laravel Socialite通过Google API登录用户。
一切配置看似正常和平凡,但我不断得到错误Missing required parameter: client_id
。不仅如此,有时我再次尝试,尽管提供了所有这些参数,但错误变成了Missing required parameter: redirect_uri
。
这就是它的设置方式:
service.php
'google' => [
'client_id' => 'xxxxxxxxxx-x98asxxxx913ofk5tqvgq7lqfpgdi5u2.apps.googleusercontent.com',
'client_secret' => 'mklOWJFhpbCzTKxxxx-xxxx',
'redirect' => 'http://myapp.com/auth/google/callback'
],
routes.php文件
Route::get('/auth/{social_channel}', 'Auth\AuthController@redirect_to_provider');
Route::get('/auth/{social_channel}/callback', 'Auth\AuthController@handle_provider_callback');
AuthController.php
/**
* Redirect the user to the Google authentication page.
*
* @return Response
*/
public function redirect_to_provider($social_channel)
{
return Socialite::driver($social_channel)->redirect();
}
/**
* Obtain the user information from GitHub.
*
* @return Response
*/
public function handle_provider_callback($social_channel, SocialAccountService $service)
{
$user = $service->create_or_get_user($social_channel, Socialite::driver($social_channel)->user());
Auth::login($user);
return redirect()->to('/go');
}
Facebook登录对我有用,只是这个谷歌登录问题是一个顽固和奇怪的问题。
该应用程序部署在Forge(Ubuntu,Nginx)上。
任何人都可以发现任何错误吗?
使用env()
文件中的services.php
函数,您必须在.env
文件中使用GOOGLE_CLIENT_ID和GOOGLE_CLIENT_SECRET,而不使用空格。
GOOGLE_CLIENT_ID=xxxxxxxxxxxx
GOOGLE_CLIENT_SECRET=xxxxxxxxxxxxxx
在services文件中,使用它
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
我刚刚解决了同样的问题,我的第一个解决方案是使用->with()
在控制器上传递client_id和secret。代码是这样的:
return Socialite::driver('google')
->with(
['client_id' => 'xxxxxxxx'],
['client_secret' => 'xxxxxxxx'],
['redirect' => 'http://localhost:8000/Yourcallback'])
->redirect();
或者只是删除services.php上的env()
'client_id' => env('xxxxxxx'),
'client_secret' => env('xxxxxxx'),
有了这个
'client_id' => 'xxxxxxx',
'client_secret' => 'xxxxxxx',
似乎社交名媛没有认识到qazxsw poi的功能。