1. Go to this page and download the library: Download renoki-co/hej 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/ */
renoki-co / hej example snippets
use RenokiCo\Hej\Concerns\HasSocialAccounts;
use RenokiCo\Hej\Contracts\Sociable;
class User extends Authenticatable implements Sociable
{
use HasSocialAccounts;
//
}
/**
* Get the Socialite direct instance that will redirect
* the user to the right provider OAuth page.
*
* @param \Illuminate\Http\Request $request
* @param string $provider
* @return mixed
*/
protected function getSocialiteRedirect(Request $request, string $provider)
{
return $this->socialite
->driver($provider)
->redirect();
}
/**
* Get the Socialite User instance that will be
* given after the OAuth authorization passes.
*
* @param \Illuminate\Http\Request $request
* @param string $provider
* @return \Laravel\Socialite\AbstractUser
*/
protected function getSocialiteUser(Request $request, string $provider)
{
return $this->socialite
->driver($provider)
->user();
}
/**
* Get the Authenticatable model data to fill on register.
* When the user gets created, it will receive these parameters
* in the `::create()` method.
*
* @param \Illuminate\Http\Request $request
* @param string $provider
* @param \Laravel\Socialite\AbstractUser $providerUser
* @return array
*/
protected function getRegisterData(Request $request, string $provider, $providerUser): array
{
return [
'name' => $providerUser->getName(),
'email' => $providerUser->getEmail(),
'email_verified_at' => now(),
'password' => Hash::make(Str::random(64)),
];
}
/**
* Get the Social model data to fill on register or login.
*
* @param \Illuminate\Http\Request $request
* @param string $provider
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Laravel\Socialite\AbstractUser $providerUser
* @return array
*/
protected function getSocialData(Request $request, string $provider, $model, $providerUser): array
{
return [
'provider_nickname' => $providerUser->getNickname(),
'provider_name' => $providerUser->getName(),
'provider_email' => $providerUser->getEmail(),
'provider_avatar' => $providerUser->getAvatar(),
];
}
/**
* Handle the callback after the registration process.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Illuminate\Database\Eloquent\Model $social
* @param \Laravel\Socialite\AbstractUser $providerUser
* @return void
*/
protected function registered(Request $request, $model, $social, $providerUser)
{
//
}
/**
* Handle the callback after the login process.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Illuminate\Database\Eloquent\Model $social
* @param \Laravel\Socialite\AbstractUser $providerUser
* @return void
*/
protected function authenticated(Request $request, $model, $social, $providerUser)
{
//
}
/**
* Handle the callback after the linking process.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Illuminate\Database\Eloquent\Model $social
* @param \Laravel\Socialite\AbstractUser $providerUser
* @return void
*/
protected function linked(Request $request, $model, $social, $providerUser)
{
//
}
/**
* Handle the callback after the unlink process.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $provider
* @return void
*/
protected function unlinked(Request $request, $model, string $provider)
{
//
}
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
/**
* Specify the redirection route after successful authentication.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Http\RedirectResponse
*/
protected function redirectToAfterAuthentication($model)
{
return Redirect::route('home');
}
/**
* Specify the redirection route to let the users know
* the authentication using the selected provider was rejected.
*
* @param \Illuminate\Http\Request $request
* @param string $provider
* @return \Illuminate\Http\RedirectResponse
*/
protected function redirectToAfterProviderIsRejected(Request $request, $provider)
{
return Redirect::route('home');
}
/**
* Specify the redirection route to let the users know
* the E-Mail address used with this social account is
* already existent as another account. This is most often
* occuring during registrations with Social accounts.
*
* @param \Illuminate\Http\Request $request
* @param string $provider
* @param \Laravel\Socialite\AbstractUser $providerUser
* @return \Illuminate\Http\RedirectResponse
*/
protected function redirectToAfterDuplicateEmail(Request $request, $provider, $providerUser)
{
return Redirect::route('home');
}