Skip to content

Commit

Permalink
oauth support skips authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Mar 16, 2024
1 parent 5ac5e83 commit 3e96d18
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/Filament/Resources/Oauth/ClientResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Resources\Oauth;

use App\Filament\OptionsTrait;
use App\Filament\PageListSingle;
use App\Filament\Resources\Oauth\ClientResource\Pages;
use App\Filament\Resources\Oauth\ClientResource\RelationManagers;
Expand All @@ -16,6 +17,8 @@

class ClientResource extends Resource
{
use OptionsTrait;

protected static ?string $model = Client::class;

protected static ?string $navigationIcon = 'heroicon-o-collection';
Expand All @@ -40,6 +43,11 @@ public static function form(Form $form): Form
->schema([
Forms\Components\TextInput::make('name')->label(__('label.name')),
Forms\Components\TextInput::make('redirect')->label(__('oauth.redirect')),
Forms\Components\Radio::make('skips_authorization')
->options(self::getYesNoOptions())
->inline()
->default(0)
->label(__('oauth.skips_authorization')),

]);
}
Expand All @@ -52,6 +60,10 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('name')->label(__('label.name')),
Tables\Columns\TextColumn::make('secret')->label(__('oauth.secret')),
Tables\Columns\TextColumn::make('redirect')->label(__('oauth.redirect')),
Tables\Columns\IconColumn::make('skips_authorization')
->boolean()
->label(__('oauth.skips_authorization'))
,

])
->filters([
Expand Down
13 changes: 13 additions & 0 deletions app/Models/OauthClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Models;

use Laravel\Passport\Client;

class OauthClient extends Client
{
public function skipsAuthorization(): bool
{
return (bool)$this->skips_authorization;
}
}
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Resources\Json\JsonResource;
use Laravel\Passport\Passport;
use Nexus\Nexus;
use Filament\Facades\Filament;
use NexusPlugin\Menu\Filament\MenuItemResource;
Expand All @@ -22,6 +23,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
Passport::ignoreMigrations();
do_action('nexus_register');
}

Expand Down
3 changes: 3 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\Codec;
use App\Models\Icon;
use App\Models\Media;
use App\Models\OauthClient;
use App\Models\Plugin;
use App\Models\Processing;
use App\Models\SearchBox;
Expand All @@ -21,6 +22,7 @@
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Laravel\Passport\Passport;

class AuthServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -54,6 +56,7 @@ class AuthServiceProvider extends ServiceProvider
public function boot()
{
$this->registerPolicies();
Passport::useClientModel(OauthClient::class);

Auth::viaRequest('nexus-cookie', function (Request $request) {
return $this->getUserByCookie($request->cookie());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('oauth_auth_codes', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->unsignedBigInteger('user_id')->index();
$table->unsignedBigInteger('client_id');
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_auth_codes');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('oauth_access_tokens', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->unsignedBigInteger('user_id')->nullable()->index();
$table->unsignedBigInteger('client_id');
$table->string('name')->nullable();
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->timestamps();
$table->dateTime('expires_at')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_access_tokens');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->string('access_token_id', 100)->index();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_refresh_tokens');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('oauth_clients', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->nullable()->index();
$table->string('name');
$table->string('secret', 100)->nullable();
$table->string('provider')->nullable();
$table->text('redirect');
$table->boolean('personal_access_client');
$table->boolean('password_client');
$table->boolean('revoked');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_clients');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('oauth_personal_access_clients', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('client_id');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_personal_access_clients');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('oauth_clients', function (Blueprint $table) {
$table->boolean("skips_authorization")->default(false);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('oauth_clients', function (Blueprint $table) {
$table->dropColumn("skips_authorization");
});
}
};
2 changes: 1 addition & 1 deletion include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.9');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-03-16');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-03-17');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'authorization_request_desc' => 'is requesting permission to access your account',
'btn_approve' => 'Authorize',
'btn_deny' => 'Cancel',
'skips_authorization' => 'Skips authorization',
];
1 change: 1 addition & 0 deletions resources/lang/zh_CN/oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'authorization_request_desc' => '正在请求获取您账号的访问权限',
'btn_approve' => '授权',
'btn_deny' => '取消',
'skips_authorization' => '跳过授权',
];
1 change: 1 addition & 0 deletions resources/lang/zh_TW/oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'authorization_request_desc' => '正在請求獲取您賬號的訪問權限',
'btn_approve' => '授權',
'btn_deny' => '取消',
'skips_authorization' => '跳過授權',
];

0 comments on commit 3e96d18

Please sign in to comment.