finish basic oauth authentication
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
||||||
#[Fillable(['name', 'email', 'oauth_token'])]
|
#[Fillable(['id', 'name', 'email', 'oauth_token'])]
|
||||||
#[Hidden(['remember_token'])]
|
#[Hidden(['remember_token'])]
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ return new class extends Migration
|
|||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::create('users', function (Blueprint $table) {
|
Schema::create('users', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->string('id', 64)->primary();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('email')->unique();
|
$table->string('email')->unique();
|
||||||
$table->timestamp('email_verified_at')->nullable();
|
$table->timestamp('email_verified_at')->nullable();
|
||||||
|
|||||||
+19
-15
@@ -8,20 +8,24 @@ Route::get('/', function () {
|
|||||||
return view('welcome');
|
return view('welcome');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::prefix('auth')->group(function () {
|
||||||
Route::get('/auth/login', function () {
|
Route::get('login', function () {
|
||||||
return Socialite::driver('authentik')->redirect();
|
return Socialite::driver('authentik')->redirect();
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/auth/redirect', function () {
|
Route::get('/redirect', function () {
|
||||||
$user = Socialite::driver('authentik')->user();
|
$user = Socialite::driver('authentik')->user();
|
||||||
$new_user = User::updateOrCreate([
|
$new_user = User::updateOrCreate([
|
||||||
'name' => $user->nickname,
|
'id' => $user->id,
|
||||||
'email' => $user->email,
|
], [
|
||||||
'oauth_token' => $user->token,
|
'id' => $user->id,
|
||||||
]);
|
'name' => $user->nickname,
|
||||||
Auth::login($new_user);
|
'email' => $user->email,
|
||||||
|
'oauth_token' => $user->token,
|
||||||
|
]);
|
||||||
|
Auth::login($new_user);
|
||||||
|
|
||||||
return view('welcome', ['user'=>$user->name]);
|
return redirect('/');
|
||||||
// $user->token
|
// $user->token
|
||||||
});
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user