diff --git a/app/Http/Livewire/Dashboard.php b/app/Http/Livewire/Dashboard.php index 723b00f7f..b46df481a 100644 --- a/app/Http/Livewire/Dashboard.php +++ b/app/Http/Livewire/Dashboard.php @@ -17,6 +17,10 @@ public function mount() $this->servers = Server::ownedByCurrentTeam()->get(); $this->projects = Project::ownedByCurrentTeam()->get(); } + // public function createToken() { + // $token = auth()->user()->createToken('test'); + // ray($token); + // } // public function getIptables() // { // $servers = Server::ownedByCurrentTeam()->get(); diff --git a/app/Models/PersonalAccessToken.php b/app/Models/PersonalAccessToken.php new file mode 100644 index 000000000..f5b11883a --- /dev/null +++ b/app/Models/PersonalAccessToken.php @@ -0,0 +1,15 @@ +teams()->attach($new_team, ['role' => 'owner']); }); } + public function createToken(string $name, array $abilities = ['*'], DateTimeInterface $expiresAt = null) + { + ray('asd'); + $plainTextToken = sprintf( + '%s%s%s', + config('sanctum.token_prefix', ''), + $tokenEntropy = Str::random(40), + hash('crc32b', $tokenEntropy) + ); + $token = $this->tokens()->create([ + 'name' => $name, + 'token' => hash('sha256', $plainTextToken), + 'abilities' => $abilities, + 'expires_at' => $expiresAt, + 'team_id' => session('currentTeam')->id + ]); + + return new NewAccessToken($token, $token->getKey().'|'.$plainTextToken); + } public function teams() { return $this->belongsToMany(Team::class)->withPivot('role'); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 07d02cd03..c50a53bef 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,8 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\ServiceProvider; +use Laravel\Sanctum\Sanctum; +use App\Models\PersonalAccessToken; class AppServiceProvider extends ServiceProvider { @@ -13,6 +15,8 @@ public function register(): void public function boot(): void { + Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class); + Http::macro('github', function (string $api_url, string|null $github_access_token = null) { if ($github_access_token) { return Http::withHeaders([ diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index e6a7cf975..7ceb40d7a 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -62,7 +62,7 @@ @endforeach @if ($projects->count() > 0) -

Servers

+

Servers

@endif @if ($servers->count() === 1)
@@ -97,7 +97,9 @@ @endforeach
- + {{--

Tokens

+ {{auth()->user()->tokens}} + Create Token --}}