PHP code example of gusmanwidodo / auth-kit-social
1. Go to this page and download the library: Download gusmanwidodo/auth-kit-social 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/ */
gusmanwidodo / auth-kit-social example snippets
'providers' => ['github', 'google'],
// In any plugin implementing HasHooks, or an app service provider that
// registers into the AuthManager registry:
public function beforeHooks(): array
{
return [
'social.login' => function ($ctx) {
// $ctx has: provider, provider_id, email, name, nickname
$user = User::firstOrCreate(
['email' => $ctx->get('email')],
['name' => $ctx->get('name')],
);
$ctx->set('subject_type', User::class)->set('subject_id', $user->id);
// To reject: $ctx->set('allow', false)->stop();
},
];
}
use Gusmanwidodo\AuthKitSocial\SocialManager;
$social = app(SocialManager::class);
// After Socialite returns a user:
$identity = $social->authenticate('github', $socialiteUser);
// Link another provider to a known subject (e.g. "connect account"):
$social->link('google', $socialiteUser, User::class, $user->id);
// Unlink:
$social->unlink('github', User::class, $user->id);
// All identities for a subject:
$social->identitiesFor(User::class, $user->id);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.