nog*_*ias 8 php nginx google-api laravel laravel-socialite
我有一个奇怪的问题,使用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'
],
Run Code Online (Sandbox Code Playgroud)
routes.php文件
Route::get('/auth/{social_channel}', 'Auth\AuthController@redirect_to_provider');
Route::get('/auth/{social_channel}/callback', 'Auth\AuthController@handle_provider_callback');
Run Code Online (Sandbox Code Playgroud)
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');
}
Run Code Online (Sandbox Code Playgroud)
Facebook登录对我有用,只是这个谷歌登录问题是一个顽固和奇怪的问题.
该应用程序部署在Forge(Ubuntu,Nginx)上.
任何人都可以发现任何错误吗?
env()在services.php文件中具有功能的情况下,您必须在文件中使用GOOGLE_CLIENT_ID和GOOGLE_CLIENT_SECRET,且不能使用.env空格。
GOOGLE_CLIENT_ID=xxxxxxxxxxxx
GOOGLE_CLIENT_SECRET=xxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
在服务文件中,使用此
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
Run Code Online (Sandbox Code Playgroud)
我刚刚解决了同样的问题,我的第一个解决方案是使用->with(). 代码是这样的:
return Socialite::driver('google')
->with(
['client_id' => 'xxxxxxxx'],
['client_secret' => 'xxxxxxxx'],
['redirect' => 'http://localhost:8000/Yourcallback'])
->redirect();
Run Code Online (Sandbox Code Playgroud)
或者只是通过删除env()services.php
'client_id' => env('xxxxxxx'),
'client_secret' => env('xxxxxxx'),
Run Code Online (Sandbox Code Playgroud)
有了这个
'client_id' => 'xxxxxxx',
'client_secret' => 'xxxxxxx',
Run Code Online (Sandbox Code Playgroud)
看来Socialite 并没有recoginizedenv()功能。
| 归档时间: |
|
| 查看次数: |
2740 次 |
| 最近记录: |