Last active
August 19, 2022 08:18
-
-
Save azophy/74e627773f47471dd26727d959d2708c to your computer and use it in GitHub Desktop.
This file contains 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 | |
namespace App\Http\Controllers; | |
use App\Models\User; | |
use Illuminate\Support\Facades\Auth; | |
use Laravel\Socialite\Facades\Socialite; | |
class AuthController extends Controller | |
{ | |
public function redirect() | |
{ | |
return Socialite::driver('keycloak')->redirect(); | |
} | |
public function callback() | |
{ | |
$keycloakUser = Socialite::driver('keycloak')->user(); | |
// Buat model Laravel sesuai data dari keycloak. Di lapangan umumnya di sini akan | |
// dilakukan update database berdasarkan data terbaru dari Keycloak, namun karena | |
// di sini tidak menggunakan database, maka model User ini tidak perlu di simpan. | |
$user = new User([ | |
'name' => $keycloakUser->user['preferred_username'], | |
'email' => $keycloakUser->user['email'], | |
'password' => '', // field ini by default adalah required & tidak nullable. karena tidak terpakai jadi kita kosongkan saja | |
]); | |
// login user dari keycloak | |
Auth::login($user); | |
return redirect('/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment