Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #19

Closed
wants to merge 10 commits into from
Closed

Main #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

66 changes: 0 additions & 66 deletions .github/ISSUE_TEMPLATE/bug.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/ISSUE_TEMPLATE/config.yml

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/test-stubs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: run-tests

on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.2]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
carbon: ^2.63

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Setup Laravel
run: |
composer create-project laravel/laravel:^${{ matrix.laravel }} .
composer require laravel/jetstream:@dev --no-interaction --no-update
compsoser require headerx/laravel-jetstream-passport:@dev --no-interaction --no-update
composer config repositories.laravel-jetstream-passport '{"type": "path", "url": "laravel-jetstream-passport"}' --file composer.json

- name: Checkout code
uses: actions/checkout@v4
with:
path: laravel-jetstream-passport

- name: Install Jetstream
run: |
composer update "laravel/jetstream" --prefer-dist --no-interaction --no-progress -W
php artisan jetstream:install livewire --api --dark --pest --no-interaction

- name: Install Jetsream Passport
run: |
composer update "headerx/laravel-jetstream-passport" --prefer-dist --no-interaction --no-progress -W
php artisan jetstream-passport:install -v

- name: List Installed Dependencies
run: composer show -D

- name: Install NPM dependencies
run: npm install

- name: Compile assets
run: npm run dev

- name: Execute tests
run: vendor/bin/pest
env:
DB_CONNECTION: sqlite
DB_DATABASE: ":memory:"
38 changes: 38 additions & 0 deletions src/Commands/JetstreamPassportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace HeaderX\JetstreamPassport\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class JetstreamPassportCommand extends Command
{
Expand All @@ -16,5 +17,42 @@ public function handle()
$this->call('passport:keys');
$this->call('passport:install', ['--uuids']);
$this->call('passport:client', ['--personal' => true, '--name' => 'Laravel Personal Access Client']);

$this->replaceInFile('Laravel\\Sanctum\\HasApiTokens', 'Laravel\\Passport\\HasApiTokens', app_path('Models/User.php'));

$this->copyFiles();
}

/**
* Replace a given string within a given file.
*
* @param string $search
* @param string $replace
* @param string $path
* @return void
*/
protected function replaceInFile($search, $replace, $path)
{
file_put_contents($path, str_replace($search, $replace, file_get_contents($path)));
}

protected function copyFiles()
{
$this->info('Copying files...');

$sourceDir = realpath(__DIR__.'/../../stubs/');
$destinationDir = base_path();

$files = File::allFiles($sourceDir);

foreach ($files as $file) {
$destinationFilePath = $destinationDir.'/'.$file->getRelativePathname();
File::ensureDirectoryExists(dirname($destinationFilePath));
File::copy($sourceFile = $file->getPathname(), $destinationFilePath);
// check verbosity
if ($this->output->isVerbose()) {
$this->line('<info>Copied</info> '.$sourceFile.' <info>to</info> '.$destinationFilePath);
}
}
}
}
38 changes: 38 additions & 0 deletions stubs/app/Providers/PassportServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport;

class PassportServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
Passport::tokensCan([
'create' => 'Create resources',
'read' => 'Read Resources',
'update' => 'Update Resources',
'delete' => 'Delete Resources',
]);

// default scope for passport tokens
Passport::setDefaultScope([
// 'create',
'read',
// 'update',
// 'delete',
]);
}
}
10 changes: 10 additions & 0 deletions stubs/bootstrap/providers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// This file is automatically generated by Laravel...

return [
App\Providers\AppServiceProvider::class,
App\Providers\FortifyServiceProvider::class,
App\Providers\JetstreamServiceProvider::class,
App\Providers\PassportServiceProvider::class,
];
121 changes: 121 additions & 0 deletions stubs/config/auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option defines the default authentication "guard" and password
| reset "broker" for your application. You may change these values
| as required, but they're a perfect start for most applications.
|
*/

'defaults' => [
'guard' => env('AUTH_GUARD', 'web'),
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
],

/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| which utilizes session storage plus the Eloquent user provider.
|
| All authentication guards have a user provider, which defines how the
| users are actually retrieved out of your database or other storage
| system used by the application. Typically, Eloquent is utilized.
|
| Supported: "session"
|
*/

'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],

'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
],

/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication guards have a user provider, which defines how the
| users are actually retrieved out of your database or other storage
| system used by the application. Typically, Eloquent is utilized.
|
| If you have multiple user tables or models you may configure multiple
| providers to represent the model / table. These providers may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/

'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', App\Models\User::class),
],

// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],

/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| These configuration options specify the behavior of Laravel's password
| reset functionality, including the table utilized for token storage
| and the user provider that is invoked to actually retrieve users.
|
| The expiry time is the number of minutes that each reset token will be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
| The throttle setting is the number of seconds a user must wait before
| generating more password reset tokens. This prevents the user from
| quickly generating a very large amount of password reset tokens.
|
*/

'passwords' => [
'users' => [
'provider' => 'users',
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
'expire' => 60,
'throttle' => 60,
],
],

/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| window expires and users are asked to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/

'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),

];
Loading