-
-
Save bosunski/14c2028836de9daf8df50f00dcb40a54 to your computer and use it in GitHub Desktop.
2018-09_How_to_use_multiple_callbacks_in_Laravel_Socialite.blade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FACEBOOK_CLIENT_ID=693724864165765 | |
FACEBOOK_CLIENT_SECRET=90d9ddf7dd76aa7a3dfac90b433c4273 | |
FACEBOOK_CLIENT_CALLBACK=/login/facebook/callback |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
//... | |
'facebook' => [ | |
'client _id' => env('FACEBOOK_CLIENT_ID'), | |
'client_secret' => env('FACEBOOK_CLIENT_SECRET'), | |
'redirect' => env('FACEBOOK_CLIENT_CALLBACK'), | |
], | |
// ... | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SocialLoginController.php | |
// ... | |
public function redirectToProvider($provider) | |
{ | |
Socialite::driver($provider)->redirect(); | |
} | |
//... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SocialLoginController.php | |
// ... | |
public function handleProviderCallback() | |
{ | |
$user = Socialite::driver($provider)->user(); | |
return $user; | |
} | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// routes.php | |
Route::get('login/{provider}', 'SocialLoginController@redirectToProvider')->name('socialLogin'); | |
Route::get('login/{provider}/callback', 'SocialLoginController@handleProviderCallback')->name('socialLoginCallback'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// routes.php | |
Route::get('login/{provider}', 'SocialLoginController@redirectToProvider')->name('socialLogin'); | |
Route::get('login/{provider}/callback', 'SocialLoginController@handleProviderCallback')->name('socialLoginCallback'); | |
Route::get('register/{provider}', 'SocialRegisterationController@redirectToProvider')->name('socialRegister'); | |
Route::get('register/{provider}/callback', 'SocialRegisterationController@handleProviderCallback')->name('socialRegisterCallback'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// config/services.php | |
'facebook' => [ | |
'client _id' => env('FACEBOOK_CLIENT_ID'), | |
'client_secret' => env('FACEBOOK_CLIENT_SECRET'), | |
'redirect' => env('FACEBOOK_CLIENT_CALLBACK'), | |
], | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SocialLoginController.php | |
namespace App\Http\Controller; | |
use App\Traits\CanBuildSocialProvider; | |
class SocialLoginController extends Controller | |
{ | |
use CanbuildSocialProvider; | |
public function redirectToProvider($provider) | |
{ | |
$this->provider = $provider; | |
$redirectUrl = '/login/facebook/callback'; | |
return $this->buildSocialProvider($redirectUrl)->redirect(); | |
} | |
public function handleProviderCallback($provider) | |
{ | |
$this->provider = $provider; | |
$redirectUrl = '/login/facebook/callback'; | |
$user = $this->buildSocialProvider($redirectUrl)->user(); | |
// Do login processing | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SocialRegistrationController.php | |
namespace App\Http\Controller; | |
use App\Traits\CanBuildSocialProvider; | |
class SocialLoginController extends Controller | |
{ | |
use CanbuildSocialProvider; | |
public function redirectToProvider($provider) | |
{ | |
$this->provider = $provider; | |
$redirectUrl = '/register/facebook/callback'; | |
return $this->buildSocialProvider($redirectUrl)->redirect(); | |
} | |
public function handleProviderCallback($provider) | |
{ | |
$this->provider = $provider; | |
$redirectUrl = '/register/facebook/callback'; | |
$user = $this->buildSocialProvider($redirectUrl)->user(); | |
// Do registration processing | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment