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\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'oauth_token'])]
|
||||
#[Fillable(['id', 'name', 'email', 'oauth_token'])]
|
||||
#[Hidden(['remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('id', 64)->primary();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
|
||||
+8
-4
@@ -8,20 +8,24 @@ Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
|
||||
|
||||
Route::get('/auth/login', function () {
|
||||
Route::prefix('auth')->group(function () {
|
||||
Route::get('login', function () {
|
||||
return Socialite::driver('authentik')->redirect();
|
||||
});
|
||||
|
||||
Route::get('/auth/redirect', function () {
|
||||
Route::get('/redirect', function () {
|
||||
$user = Socialite::driver('authentik')->user();
|
||||
$new_user = User::updateOrCreate([
|
||||
'id' => $user->id,
|
||||
], [
|
||||
'id' => $user->id,
|
||||
'name' => $user->nickname,
|
||||
'email' => $user->email,
|
||||
'oauth_token' => $user->token,
|
||||
]);
|
||||
Auth::login($new_user);
|
||||
|
||||
return view('welcome', ['user'=>$user->name]);
|
||||
return redirect('/');
|
||||
// $user->token
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user