PHP code example of chuoke / laravel-user-identify
1. Go to this page and download the library: Download chuoke/laravel-user-identify library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Chuoke\UserIdentify\UserIdentifyProvider;
use Illuminate\Contracts\Foundation\Application;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Auth::provider(config('user-identify.auth_provider_name'), function (Application $app, array $config) {
return new UserIdentifyProvider(
$app['hash'],
config('user-identify.user_model'),
config('user-identify.idetifier_model'),
);
});
}
}
namespace App\Web\Controllers\Auth;
use Illuminate\Http\Request;
use App\Web\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
class GithubController extends Controller
{
public function redirect(Request $request)
{
return Socialite::driver('github')->redirect();
}
public function callback(Request $request)
{
/** @var \Laravel\Socialite\AbstractUser $githubUser */
$githubUser = Socialite::driver('github')->user();
$githubUser['socialite_type'] = 'github';
$successful = Auth::attempt([
'identifier' => $githubUser,
], true);
if ($successful) {
return redirect('/dashboard');
}
return redirect('/login');
}
}