我在信中跟随this repository,但是我无法与Vue的社交场所开始会话。我的示例是在laravel和与框架集成的vue中,如果我设法开始会话,则调解Laravel,但我想使用Laravel作为api。
/* RUTA PARA PROBAR EL INICIO DE SESION POR VUE */
/* ROUTE TO TRY THE START OF SESSION BY VUE */
Route::post('sociallogin/{provider}', 'Auth\AuthController@SocialSignup');
Route::get('login/{driver}', 'OutController@index')->where('vue', '.*');
Route::get('login/{driver}/callback', 'OutController@index')->where('vue', '.*');
/* RUTA PARA PROBAR EL INICIO DE SESION POR LARAVEL */
/* ROUTE TO TEST THE START OF A SESSION BY LARAVEL */
Route::get('login/{driver}', 'Auth\AuthController@redirectToProvider')->name('social_auth');
Route::get('login/{driver}/callback', 'Auth\AuthController@handleProviderCallback');
/* VUE */
public function SocialSignup($provider)
{
// Socialite will pick response data automatic
$user = Socialite::driver($provider)->stateless()->user();
return response()->json($user);
}
/* LARAVEL */
public function redirectToProvider (string $driver)
{
return Socialite::driver($driver)->redirect();
}
/* LARAVEL */
public function handleProviderCallback (string $driver)
{
if( ! request()->has('code') || request()->has('denied')) {
return response()->json('Inicio de sesión cancelado');
}
$socialUser = Socialite::driver($driver)->user();
return response()->json($socialUser);
}