PHP code example of affinidi / laravel-hybridauth-affinidi
1. Go to this page and download the library: Download affinidi/laravel-hybridauth-affinidi 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/ */
affinidi / laravel-hybridauth-affinidi example snippets
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginRegisterController extends Controller
{
private static $adapter;
public function __construct() {
$config = \Config::get('hybridauth.affinidi');
self::$adapter = new \Affinidi\HybridauthProvider\AffinidiProvider($config);
}
public function login()
{
return view('login');
}
public function home()
{
if (session("user")) {
return view('dashboard');
}
return redirect()->route('login')
->withErrors([
'email' => 'Please login to access the home.',
]);
}
public function logout(Request $request)
{
self::$adapter->disconnect();
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect()->route('login')
->withSuccess('You have logged out successfully!');
;
}
public function affinidiLogin(Request $request)
{
self::$adapter->authenticate();
}
public function affinidiCallback(Request $request)
{
try {
self::$adapter->authenticate();
$userProfile = self::$adapter->getUserProfile();
session(['user' => $userProfile]);
return redirect()->intended('home');
} catch (\Exception $e) {
return redirect()->route('login')
->withError($e->getMessage());
}
}
}
php artisan serve
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.