From 600526a3f2a9596cdf706400881af5e9764f0cd8 Mon Sep 17 00:00:00 2001 From: karimalik Date: Mon, 25 Dec 2023 12:34:16 +0100 Subject: [PATCH 1/8] add passport package --- README.md | 84 +------ app/Console/Commands/.gitkeep | 0 app/Enum/Error.php | 13 ++ app/Exceptions/.gitkeep | 0 app/Http/Controllers/HomeController.php | 20 ++ app/Http/Controllers/V1/.gitkeep | 0 app/Http/Middleware/CacheHeaders.php | 48 ++++ app/Http/Middleware/ContentTypeMiddleware.php | 27 +++ app/Http/Middleware/EncryptCookies.php | 12 + app/Http/Middleware/EnsureEmailIsVerified.php | 24 ++ .../PreventRequestsDuringMaintenance.php | 12 + .../Security/XFrameOptionMiddleware.php | 26 +++ app/Http/Middleware/TrimStrings.php | 21 ++ app/Http/Middleware/TrustProxies.php | 25 ++ app/Http/Middleware/ValidateSignature.php | 12 + app/Http/Resources/ApiErrorResponse.php | 35 +++ app/Http/Resources/DateResource.php | 23 ++ app/Http/Resources/V1/.gitkeep | 0 app/Models/User.php | 33 +++ artisan | 53 +++++ bootstrap/app.php | 57 +++++ bootstrap/cache/.gitignore | 2 + composer.json | 77 +++++- config/app.php | 219 ++++++++++++++++++ config/auth.php | 117 ++++++++++ config/broadcasting.php | 72 ++++++ config/cache.php | 112 +++++++++ config/cors.php | 36 +++ config/database.php | 153 ++++++++++++ config/filesystems.php | 78 +++++++ config/hashing.php | 54 +++++ config/headers.php | 22 ++ config/logging.php | 125 ++++++++++ config/mail.php | 126 ++++++++++ config/queue.php | 95 ++++++++ config/sanctum.php | 54 +++++ config/services.php | 36 +++ config/session.php | 203 ++++++++++++++++ config/treblle.php | 36 +++ config/view.php | 38 +++ core/Console/Kernel.php | 25 ++ core/Exceptions/Handler.php | 28 +++ core/Http/Controllers/Controller.php | 15 ++ core/Http/Kernel.php | 68 ++++++ core/Providers/AppServiceProvider.php | 15 ++ core/Providers/AuthServiceProvider.php | 18 ++ core/Providers/BroadcastServiceProvider.php | 17 ++ core/Providers/EventServiceProvider.php | 18 ++ core/Providers/RouteServiceProvider.php | 39 ++++ database/.gitignore | 1 + database/factories/UserFactory.php | 35 +++ .../2014_10_12_000000_create_users_table.php | 28 +++ ...000_create_password_reset_tokens_table.php | 23 ++ ..._08_19_000000_create_failed_jobs_table.php | 27 +++ ...01_create_personal_access_tokens_table.php | 30 +++ database/seeders/DatabaseSeeder.php | 19 ++ lang/en/auth.php | 22 ++ lang/en/messages.php | 9 + lang/en/pagination.php | 21 ++ lang/en/passwords.php | 24 ++ lang/en/validation.php | 186 +++++++++++++++ lang/fr/messages.php | 9 + phpstan.neon | 21 ++ phpunit.xml | 37 +-- pint.json | 42 ++++ public/.htaccess | 21 ++ public/favicon.ico | 0 public/index.php | 57 +++++ public/robots.txt | 2 + resources/views/.gitkeep | 1 + routes/api/routes.php | 12 + routes/api/v1/api.php | 7 + routes/sockets/routes.php | 11 + storage/app/.gitignore | 3 + storage/app/public/.gitignore | 2 + storage/framework/.gitignore | 9 + storage/framework/cache/.gitignore | 3 + storage/framework/cache/data/.gitignore | 2 + storage/framework/sessions/.gitignore | 2 + storage/framework/testing/.gitignore | 2 + storage/framework/views/.gitignore | 2 + storage/logs/.gitignore | 2 + stubs/cast.stub | 31 +++ stubs/console.stub | 19 ++ stubs/controller.invokable.stub | 15 ++ stubs/event.stub | 35 +++ stubs/factory.stub | 19 ++ stubs/job.queued.stub | 27 +++ stubs/mail.stub | 41 ++++ stubs/markdown-mail.stub | 41 ++++ stubs/markdown-notification.stub | 50 ++++ stubs/middleware.stub | 17 ++ stubs/migration.create.stub | 26 +++ stubs/migration.stub | 20 ++ stubs/migration.update.stub | 24 ++ stubs/model.pivot.stub | 12 + stubs/model.stub | 19 ++ stubs/notification.stub | 41 ++++ stubs/policy.stub | 47 ++++ stubs/provider.stub | 20 ++ stubs/request.stub | 22 ++ stubs/resource.stub | 21 ++ stubs/rule.stub | 19 ++ stubs/scope.stub | 17 ++ stubs/seeder.stub | 16 ++ tests/CreatesApplication.php | 20 ++ tests/Feature/Http/Controllers/V1/.gitkeep | 0 tests/Pest.php | 11 + tests/TestCase.php | 12 + tests/Unit/.gitkeep | 0 110 files changed, 3631 insertions(+), 106 deletions(-) create mode 100644 app/Console/Commands/.gitkeep create mode 100644 app/Enum/Error.php create mode 100644 app/Exceptions/.gitkeep create mode 100644 app/Http/Controllers/HomeController.php create mode 100644 app/Http/Controllers/V1/.gitkeep create mode 100644 app/Http/Middleware/CacheHeaders.php create mode 100644 app/Http/Middleware/ContentTypeMiddleware.php create mode 100644 app/Http/Middleware/EncryptCookies.php create mode 100644 app/Http/Middleware/EnsureEmailIsVerified.php create mode 100644 app/Http/Middleware/PreventRequestsDuringMaintenance.php create mode 100644 app/Http/Middleware/Security/XFrameOptionMiddleware.php create mode 100644 app/Http/Middleware/TrimStrings.php create mode 100644 app/Http/Middleware/TrustProxies.php create mode 100644 app/Http/Middleware/ValidateSignature.php create mode 100644 app/Http/Resources/ApiErrorResponse.php create mode 100644 app/Http/Resources/DateResource.php create mode 100644 app/Http/Resources/V1/.gitkeep create mode 100644 app/Models/User.php create mode 100755 artisan create mode 100644 bootstrap/app.php create mode 100644 bootstrap/cache/.gitignore create mode 100644 config/app.php create mode 100644 config/auth.php create mode 100644 config/broadcasting.php create mode 100644 config/cache.php create mode 100644 config/cors.php create mode 100644 config/database.php create mode 100644 config/filesystems.php create mode 100644 config/hashing.php create mode 100644 config/headers.php create mode 100644 config/logging.php create mode 100644 config/mail.php create mode 100644 config/queue.php create mode 100644 config/sanctum.php create mode 100644 config/services.php create mode 100644 config/session.php create mode 100644 config/treblle.php create mode 100644 config/view.php create mode 100644 core/Console/Kernel.php create mode 100644 core/Exceptions/Handler.php create mode 100644 core/Http/Controllers/Controller.php create mode 100644 core/Http/Kernel.php create mode 100644 core/Providers/AppServiceProvider.php create mode 100644 core/Providers/AuthServiceProvider.php create mode 100644 core/Providers/BroadcastServiceProvider.php create mode 100644 core/Providers/EventServiceProvider.php create mode 100644 core/Providers/RouteServiceProvider.php create mode 100644 database/.gitignore create mode 100644 database/factories/UserFactory.php create mode 100644 database/migrations/2014_10_12_000000_create_users_table.php create mode 100644 database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php create mode 100644 database/migrations/2019_08_19_000000_create_failed_jobs_table.php create mode 100644 database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php create mode 100644 database/seeders/DatabaseSeeder.php create mode 100644 lang/en/auth.php create mode 100644 lang/en/messages.php create mode 100644 lang/en/pagination.php create mode 100644 lang/en/passwords.php create mode 100644 lang/en/validation.php create mode 100644 lang/fr/messages.php create mode 100644 phpstan.neon create mode 100644 pint.json create mode 100644 public/.htaccess create mode 100644 public/favicon.ico create mode 100644 public/index.php create mode 100644 public/robots.txt create mode 100644 resources/views/.gitkeep create mode 100644 routes/api/routes.php create mode 100644 routes/api/v1/api.php create mode 100644 routes/sockets/routes.php create mode 100644 storage/app/.gitignore create mode 100644 storage/app/public/.gitignore create mode 100644 storage/framework/.gitignore create mode 100644 storage/framework/cache/.gitignore create mode 100644 storage/framework/cache/data/.gitignore create mode 100644 storage/framework/sessions/.gitignore create mode 100644 storage/framework/testing/.gitignore create mode 100644 storage/framework/views/.gitignore create mode 100644 storage/logs/.gitignore create mode 100644 stubs/cast.stub create mode 100644 stubs/console.stub create mode 100644 stubs/controller.invokable.stub create mode 100644 stubs/event.stub create mode 100644 stubs/factory.stub create mode 100644 stubs/job.queued.stub create mode 100644 stubs/mail.stub create mode 100644 stubs/markdown-mail.stub create mode 100644 stubs/markdown-notification.stub create mode 100644 stubs/middleware.stub create mode 100644 stubs/migration.create.stub create mode 100644 stubs/migration.stub create mode 100644 stubs/migration.update.stub create mode 100644 stubs/model.pivot.stub create mode 100644 stubs/model.stub create mode 100644 stubs/notification.stub create mode 100644 stubs/policy.stub create mode 100644 stubs/provider.stub create mode 100644 stubs/request.stub create mode 100644 stubs/resource.stub create mode 100644 stubs/rule.stub create mode 100644 stubs/scope.stub create mode 100644 stubs/seeder.stub create mode 100644 tests/CreatesApplication.php create mode 100644 tests/Feature/Http/Controllers/V1/.gitkeep create mode 100644 tests/Pest.php create mode 100644 tests/TestCase.php create mode 100644 tests/Unit/.gitkeep diff --git a/README.md b/README.md index 586abb1..76cfff2 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,8 @@ -# Laravel 10 API Skeleton 📦 -This project is a skeleton for setting up an API with Laravel. It contains several ways and architectures to build an API with Laravel. +# Laravel API Skeleton - Example +This project is a skeleton for building an API with Laravel. It is the simplest skeleton and contains only the basic packages to build an API. -## Introduction 📖 -As each API project is different, it's not easy to have a boilerplate that will cover all cases. Some APIs may need roles, others may not. -Some may need to set up authentication with [Sanctum](https://laravel.com/docs/10.x/sanctum), others with [JWT](https://github.com/tymondesigns/jwt-auth), others with [Passport](https://laravel.com/docs/10.x/passport) and so on. - -All these cases are huge and complex. This project aims to build several skeletons that can be used when the need arises. -And you'll end up building the architecture you want for your next API project. - -You can see here an example of a model like Vercel with [Nextjs](https://github.com/vercel/next.js), which has several sample implementations. - -## Getting Started 🚀 -If you want to contribute to the Laravel API Skeleton repo: - -- Fork this repository to your GitHub account. Then clone your forked repository and cd into it. -- Clone the repository - ```bash - git clone https://github.com/{username}/api-skeleton.git api-skeleton && cd api-skeleton - ``` -- In your fork, create a branch for your skeleton, e.g. `feature/authentication-with-passport`. - -Then, install the dependencies `composer install` - -## Architecture 🏗 -The project has only 2 folders -- `projets` the folder where all API skeletons will be stored to start an API project with Laravel -- `skeleton` is the folder containing the commands to generate a skeleton once you've finished building it. - -## Available Skeletons 📚 -To get the list of available skeletons, run the command: - -```bash -./skeleton/bin/project available -``` - -All skeletons are available in the `projects` folder. Each skeleton is a Laravel project and containing a `composer.json` file and a `README.md` file. - - -## Usage 📝 -To create a new skeleton, run the following command: - -> To build a skeleton, you have to base it on an existing skeleton. The `default` skeleton is the simplest. -Once you've selected a skeleton, all the code in the skeleton's folder `projects/default` will be available at the root of the project, -and you'll need to do another compose install to install the Laravel project's dependencies. +## Installation ```bash -./skeleton/bin/project use {skeleton-name} +composer require laravelcm/api-skeleton ``` - -## Autoload -When you use a skeleton, it will overwrite the default root composer.json file and the commands for generating the project will no longer be available. To fix this, you need to autoload the skeleton folder using psr-4. Like this: - -```json -{ - "autoload": { - "psr-4": { - "App\\": "app/", - "Core\\": "core/", - "Skeleton\\": "skeleton/", - "Database\\Factories\\": "database/factories/", - "Database\\Seeders\\": "database/seeders/" - } - } -} -``` - -**Tip: don't forget to run composer dump-autoload afterward.** - -Once you have built your skeleton and are satisfied with your work, you can generate a project and all the modifications you have made will be added only to the skeleton you have created. - -```bash -./skeleton/bin/project generate {skeleton-name} -``` - -This command will create a new Laravel project in the `projects` folder with the name of your skeleton. And you can publish it on packagist composer or if you like. -Before pushing your branch and making a PR, you need to run the following command to reset the project to its original state. - -```bash -./skeleton/bin/project reset -``` - -## Contributing 🤝 -Feel free to create any pull requests for the project. If you have any questions, please you can create an issue. diff --git a/app/Console/Commands/.gitkeep b/app/Console/Commands/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/Enum/Error.php b/app/Enum/Error.php new file mode 100644 index 0000000..1dd303e --- /dev/null +++ b/app/Enum/Error.php @@ -0,0 +1,13 @@ + __('messages.welcome'), + ], + ); + } +} diff --git a/app/Http/Controllers/V1/.gitkeep b/app/Http/Controllers/V1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/Http/Middleware/CacheHeaders.php b/app/Http/Middleware/CacheHeaders.php new file mode 100644 index 0000000..a363563 --- /dev/null +++ b/app/Http/Middleware/CacheHeaders.php @@ -0,0 +1,48 @@ +setCache( + options: [ + 'private' => true, + 'max_age' => 0, + 's_maxage' => 0, + 'no_store' => true + ], + ); + } else { + $response->setCache( + options: [ + 'public' => true, + 'max_age' => 60, + 's_maxage' => 60, + ], + ); + + foreach ($response->headers->getCookies() as $cookie) { + $response->headers->removeCookie( + name: $cookie->getName(), + ); + } + } + + return $response; + } +} diff --git a/app/Http/Middleware/ContentTypeMiddleware.php b/app/Http/Middleware/ContentTypeMiddleware.php new file mode 100644 index 0000000..49da605 --- /dev/null +++ b/app/Http/Middleware/ContentTypeMiddleware.php @@ -0,0 +1,27 @@ +headers->add([ + 'Accept' => 'application/json', + 'Content-Type' => 'application/vnd.api+json', + ]); + + return $response; + } +} diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php new file mode 100644 index 0000000..dddc45b --- /dev/null +++ b/app/Http/Middleware/EncryptCookies.php @@ -0,0 +1,12 @@ +user() || + ($request->user() instanceof MustVerifyEmail && + ! $request->user()->hasVerifiedEmail())) { + return response()->json(['message' => __('Your email address is not verified.')], 409); + } + + return $next($request); + } +} diff --git a/app/Http/Middleware/PreventRequestsDuringMaintenance.php b/app/Http/Middleware/PreventRequestsDuringMaintenance.php new file mode 100644 index 0000000..3422e26 --- /dev/null +++ b/app/Http/Middleware/PreventRequestsDuringMaintenance.php @@ -0,0 +1,12 @@ +headers->add([ + 'X-Frame-Options' => 'deny', + ]); + + return $response; + } +} diff --git a/app/Http/Middleware/TrimStrings.php b/app/Http/Middleware/TrimStrings.php new file mode 100644 index 0000000..b7b3a49 --- /dev/null +++ b/app/Http/Middleware/TrimStrings.php @@ -0,0 +1,21 @@ + + */ + protected $except = [ + 'current_password', + 'password', + 'password_confirmation', + ]; +} diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php new file mode 100644 index 0000000..5924ec6 --- /dev/null +++ b/app/Http/Middleware/TrustProxies.php @@ -0,0 +1,25 @@ +|string|null + */ + protected $proxies; + + protected $headers = + Request::HEADER_X_FORWARDED_FOR | + Request::HEADER_X_FORWARDED_HOST | + Request::HEADER_X_FORWARDED_PORT | + Request::HEADER_X_FORWARDED_PROTO | + Request::HEADER_X_FORWARDED_AWS_ELB; +} diff --git a/app/Http/Middleware/ValidateSignature.php b/app/Http/Middleware/ValidateSignature.php new file mode 100644 index 0000000..280eac0 --- /dev/null +++ b/app/Http/Middleware/ValidateSignature.php @@ -0,0 +1,12 @@ + $this->title, + 'description' => $this->description, + 'code' => $this->code->value, + 'status' => $this->status->value, + ], + status: $this->status->value, + ); + } +} diff --git a/app/Http/Resources/DateResource.php b/app/Http/Resources/DateResource.php new file mode 100644 index 0000000..4703fd4 --- /dev/null +++ b/app/Http/Resources/DateResource.php @@ -0,0 +1,23 @@ + $this->resource->diffForHumans(), + 'string' => $this->resource->toDateTimeString(), + ]; + } +} diff --git a/app/Http/Resources/V1/.gitkeep b/app/Http/Resources/V1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/Models/User.php b/app/Models/User.php new file mode 100644 index 0000000..82d89da --- /dev/null +++ b/app/Models/User.php @@ -0,0 +1,33 @@ + 'datetime', + ]; +} diff --git a/artisan b/artisan new file mode 100755 index 0000000..67a3329 --- /dev/null +++ b/artisan @@ -0,0 +1,53 @@ +#!/usr/bin/env php +make(Illuminate\Contracts\Console\Kernel::class); + +$status = $kernel->handle( + $input = new Symfony\Component\Console\Input\ArgvInput, + new Symfony\Component\Console\Output\ConsoleOutput +); + +/* +|-------------------------------------------------------------------------- +| Shutdown The Application +|-------------------------------------------------------------------------- +| +| Once Artisan has finished running, we will fire off the shutdown events +| so that any final work may be done by the application before we shut +| down the process. This is the last thing to happen to the request. +| +*/ + +$kernel->terminate($input, $status); + +exit($status); diff --git a/bootstrap/app.php b/bootstrap/app.php new file mode 100644 index 0000000..b16512a --- /dev/null +++ b/bootstrap/app.php @@ -0,0 +1,57 @@ +singleton( + Illuminate\Contracts\Http\Kernel::class, + Core\Http\Kernel::class +); + +$app->singleton( + Illuminate\Contracts\Console\Kernel::class, + Core\Console\Kernel::class +); + +$app->singleton( + Illuminate\Contracts\Debug\ExceptionHandler::class, + Core\Exceptions\Handler::class +); + +/* +|-------------------------------------------------------------------------- +| Return The Application +|-------------------------------------------------------------------------- +| +| This script returns the application instance. The instance is given to +| the calling script so we can separate the building of the instances +| from the actual running of the application and sending responses. +| +*/ + +return $app; diff --git a/bootstrap/cache/.gitignore b/bootstrap/cache/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/bootstrap/cache/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/composer.json b/composer.json index 75f9233..3fdf50a 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,12 @@ { - "name": "laravelcm/api-skeleton", + "name": "laravelcm/api-skeleton-default", "type": "project", "description": "Skeleton for building APIs with Laravel", - "keywords": ["framework", "laravel", "api"], + "keywords": [ + "framework", + "laravel", + "api" + ], "license": "MIT", "authors": [ { @@ -13,31 +17,80 @@ } ], "require": { - "symfony/console": "^6.3", - "symfony/filesystem": "^6.3", - "symfony/finder": "^6.3" + "php": "^8.2", + "guzzlehttp/guzzle": "^7.5", + "juststeveking/http-status-code": "^3.0.2", + "juststeveking/launchpad": "dev-main", + "laravel/framework": "^10.2", + "laravel/passport": "^11.10", + "laravel/sanctum": "^3.2.1", + "laravel/tinker": "^2.8.1", + "timacdonald/json-api": "v1.0.0-beta.4", + "treblle/security-headers": "^0.0.3" }, "require-dev": { - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.6" + "fakerphp/faker": "^1.21.0", + "laravel/pint": "^1.6", + "laravel/sail": "^1.21.1", + "mockery/mockery": "^1.5.1", + "nunomaduro/collision": "^6.4", + "nunomaduro/larastan": "^2.5.1", + "pestphp/pest": "^1.22.5", + "pestphp/pest-plugin-laravel": "^1.4", + "spatie/laravel-ignition": "^2.0", + "symfony/console": "^6.3", + "symfony/filesystem": "^6.3" }, "autoload": { "psr-4": { - "Skeleton\\": "skeleton/" + "App\\": "app/", + "Core\\": "core/", + "Database\\Factories\\": "database/factories/", + "Database\\Seeders\\": "database/seeders/" } }, "autoload-dev": { "psr-4": { - "Skeleton\\Tests\\": "skeleton/tests/" + "Tests\\": "tests/" } }, + "scripts": { + "post-autoload-dump": [ + "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", + "@php artisan package:discover --ansi" + ], + "post-update-cmd": [ + "@php artisan vendor:publish --tag=laravel-assets --ansi --force" + ], + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ], + "pint": [ + "./vendor/bin/pint" + ], + "stan": [ + "./vendor/bin/phpstan analyse --memory-limit=3g" + ], + "test": [ + "@php artisan test" + ] + }, "extra": { - "branch-alias": { - "dev-master": "1.x-dev" + "laravel": { + "dont-discover": [] } }, "config": { - "sort-packages": true + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "php-http/discovery": true + } }, "minimum-stability": "dev", "prefer-stable": true diff --git a/config/app.php b/config/app.php new file mode 100644 index 0000000..5addcae --- /dev/null +++ b/config/app.php @@ -0,0 +1,219 @@ + env('APP_NAME', 'Laravel'), + + /* + |-------------------------------------------------------------------------- + | Application Environment + |-------------------------------------------------------------------------- + | + | This value determines the "environment" your application is currently + | running in. This may determine how you prefer to configure various + | services the application utilizes. Set this in your ".env" file. + | + */ + + 'env' => env('APP_ENV', 'production'), + + /* + |-------------------------------------------------------------------------- + | Application Debug Mode + |-------------------------------------------------------------------------- + | + | When your application is in debug mode, detailed error messages with + | stack traces will be shown on every error that occurs within your + | application. If disabled, a simple generic error page is shown. + | + */ + + 'debug' => (bool) env('APP_DEBUG', false), + + /* + |-------------------------------------------------------------------------- + | Application URL + |-------------------------------------------------------------------------- + | + | This URL is used by the console to properly generate URLs when using + | the Artisan command line tool. You should set this to the root of + | your application so that it is used when running Artisan tasks. + | + */ + + 'url' => env('APP_URL', 'http://localhost'), + + 'frontend_url' => env('FRONTEND_URL', 'http://localhost:3000'), + + 'asset_url' => env('ASSET_URL'), + + /* + |-------------------------------------------------------------------------- + | Application Timezone + |-------------------------------------------------------------------------- + | + | Here you may specify the default timezone for your application, which + | will be used by the PHP date and date-time functions. We have gone + | ahead and set this to a sensible default for you out of the box. + | + */ + + 'timezone' => 'UTC', + + /* + |-------------------------------------------------------------------------- + | Application Locale Configuration + |-------------------------------------------------------------------------- + | + | The application locale determines the default locale that will be used + | by the translation service provider. You are free to set this value + | to any of the locales which will be supported by the application. + | + */ + + 'locale' => 'en', + + /* + |-------------------------------------------------------------------------- + | Application Fallback Locale + |-------------------------------------------------------------------------- + | + | The fallback locale determines the locale to use when the current one + | is not available. You may change the value to correspond to any of + | the language folders that are provided through your application. + | + */ + + 'fallback_locale' => 'en', + + /* + |-------------------------------------------------------------------------- + | Faker Locale + |-------------------------------------------------------------------------- + | + | This locale will be used by the Faker PHP library when generating fake + | data for your database seeds. For example, this will be used to get + | localized telephone numbers, street address information and more. + | + */ + + 'faker_locale' => 'en_US', + + /* + |-------------------------------------------------------------------------- + | Encryption Key + |-------------------------------------------------------------------------- + | + | This key is used by the Illuminate encrypter service and should be set + | to a random, 32 character string, otherwise these encrypted strings + | will not be safe. Please do this before deploying an application! + | + */ + + 'key' => env('APP_KEY'), + + 'cipher' => 'AES-256-CBC', + + /* + |-------------------------------------------------------------------------- + | Maintenance Mode Driver + |-------------------------------------------------------------------------- + | + | These configuration options determine the driver used to determine and + | manage Laravel's "maintenance mode" status. The "cache" driver will + | allow maintenance mode to be controlled across multiple machines. + | + | Supported drivers: "file", "cache" + | + */ + + 'maintenance' => [ + 'driver' => 'file', + // 'store' => 'redis', + ], + + /* + |-------------------------------------------------------------------------- + | Autoloaded Service Providers + |-------------------------------------------------------------------------- + | + | The service providers listed here will be automatically loaded on the + | request to your application. Feel free to add your own services to + | this array to grant expanded functionality to your applications. + | + */ + + 'providers' => [ + + /* + * Laravel Framework Service Providers... + */ + Illuminate\Auth\AuthServiceProvider::class, + Illuminate\Broadcasting\BroadcastServiceProvider::class, + Illuminate\Bus\BusServiceProvider::class, + Illuminate\Cache\CacheServiceProvider::class, + Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, + Illuminate\Cookie\CookieServiceProvider::class, + Illuminate\Database\DatabaseServiceProvider::class, + Illuminate\Encryption\EncryptionServiceProvider::class, + Illuminate\Filesystem\FilesystemServiceProvider::class, + Illuminate\Foundation\Providers\FoundationServiceProvider::class, + Illuminate\Hashing\HashServiceProvider::class, + Illuminate\Mail\MailServiceProvider::class, + Illuminate\Notifications\NotificationServiceProvider::class, + Illuminate\Pagination\PaginationServiceProvider::class, + Illuminate\Pipeline\PipelineServiceProvider::class, + Illuminate\Queue\QueueServiceProvider::class, + Illuminate\Redis\RedisServiceProvider::class, + Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, + Illuminate\Session\SessionServiceProvider::class, + Illuminate\Translation\TranslationServiceProvider::class, + Illuminate\Validation\ValidationServiceProvider::class, + Illuminate\View\ViewServiceProvider::class, + + /* + * Package Service Providers... + */ + + /* + * Core Service Providers... + */ + Core\Providers\AppServiceProvider::class, + Core\Providers\AuthServiceProvider::class, + // Core\Providers\BroadcastServiceProvider::class, + Core\Providers\EventServiceProvider::class, + Core\Providers\RouteServiceProvider::class, + + ], + + /* + |-------------------------------------------------------------------------- + | Class Aliases + |-------------------------------------------------------------------------- + | + | This array of class aliases will be registered when this application + | is started. However, feel free to register as many as you wish as + | the aliases are "lazy" loaded so they don't hinder performance. + | + */ + + 'aliases' => Facade::defaultAliases()->merge([ + // 'ExampleClass' => App\Example\ExampleClass::class, + ])->toArray(), + +]; diff --git a/config/auth.php b/config/auth.php new file mode 100644 index 0000000..3fdb672 --- /dev/null +++ b/config/auth.php @@ -0,0 +1,117 @@ + [ + 'guard' => 'web', + 'passwords' => 'users', + ], + + /* + |-------------------------------------------------------------------------- + | Authentication Guards + |-------------------------------------------------------------------------- + | + | Next, you may define every authentication guard for your application. + | Of course, a great default configuration has been defined for you + | here which uses session storage and the Eloquent user provider. + | + | All authentication drivers have a user provider. This defines how the + | users are actually retrieved out of your database or other storage + | mechanisms used by this application to persist your user's data. + | + | Supported: "session" + | + */ + + 'guards' => [ + 'web' => [ + 'driver' => 'session', + 'provider' => 'users', + ], + ], + + /* + |-------------------------------------------------------------------------- + | User Providers + |-------------------------------------------------------------------------- + | + | All authentication drivers have a user provider. This defines how the + | users are actually retrieved out of your database or other storage + | mechanisms used by this application to persist your user's data. + | + | If you have multiple user tables or models you may configure multiple + | sources which represent each model / table. These sources may then + | be assigned to any extra authentication guards you have defined. + | + | Supported: "database", "eloquent" + | + */ + + 'providers' => [ + 'users' => [ + 'driver' => 'eloquent', + 'model' => App\Models\User::class, + ], + + // 'users' => [ + // 'driver' => 'database', + // 'table' => 'users', + // ], + ], + + /* + |-------------------------------------------------------------------------- + | Resetting Passwords + |-------------------------------------------------------------------------- + | + | You may specify multiple password reset configurations if you have more + | than one user table or model in the application and you want to have + | separate password reset settings based on the specific user types. + | + | 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' => 'password_reset_tokens', + 'expire' => 60, + 'throttle' => 60, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Password Confirmation Timeout + |-------------------------------------------------------------------------- + | + | Here you may define the amount of seconds before a password confirmation + | times out and the user is prompted to re-enter their password via the + | confirmation screen. By default, the timeout lasts for three hours. + | + */ + + 'password_timeout' => 10800, + +]; diff --git a/config/broadcasting.php b/config/broadcasting.php new file mode 100644 index 0000000..37d4ded --- /dev/null +++ b/config/broadcasting.php @@ -0,0 +1,72 @@ + env('BROADCAST_DRIVER', 'null'), + + /* + |-------------------------------------------------------------------------- + | Broadcast Connections + |-------------------------------------------------------------------------- + | + | Here you may define all of the broadcast connections that will be used + | to broadcast events to other systems or over websockets. Samples of + | each available type of connection are provided inside this array. + | + */ + + 'connections' => [ + + 'pusher' => [ + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), + 'options' => [ + 'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com', + 'port' => env('PUSHER_PORT', 443), + 'scheme' => env('PUSHER_SCHEME', 'https'), + 'encrypted' => true, + 'useTLS' => 'https' === env('PUSHER_SCHEME', 'https'), + ], + 'client_options' => [ + // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html + ], + ], + + 'ably' => [ + 'driver' => 'ably', + 'key' => env('ABLY_KEY'), + ], + + 'redis' => [ + 'driver' => 'redis', + 'connection' => 'default', + ], + + 'log' => [ + 'driver' => 'log', + ], + + 'null' => [ + 'driver' => 'null', + ], + + ], + +]; diff --git a/config/cache.php b/config/cache.php new file mode 100644 index 0000000..c82c508 --- /dev/null +++ b/config/cache.php @@ -0,0 +1,112 @@ + env('CACHE_DRIVER', 'file'), + + /* + |-------------------------------------------------------------------------- + | Cache Stores + |-------------------------------------------------------------------------- + | + | Here you may define all of the cache "stores" for your application as + | well as their drivers. You may even define multiple stores for the + | same cache driver to group types of items stored in your caches. + | + | Supported drivers: "apc", "array", "database", "file", + | "memcached", "redis", "dynamodb", "octane", "null" + | + */ + + 'stores' => [ + + 'apc' => [ + 'driver' => 'apc', + ], + + 'array' => [ + 'driver' => 'array', + 'serialize' => false, + ], + + 'database' => [ + 'driver' => 'database', + 'table' => 'cache', + 'connection' => null, + 'lock_connection' => null, + ], + + 'file' => [ + 'driver' => 'file', + 'path' => storage_path('framework/cache/data'), + ], + + 'memcached' => [ + 'driver' => 'memcached', + 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), + 'sasl' => [ + env('MEMCACHED_USERNAME'), + env('MEMCACHED_PASSWORD'), + ], + 'options' => [ + // Memcached::OPT_CONNECT_TIMEOUT => 2000, + ], + 'servers' => [ + [ + 'host' => env('MEMCACHED_HOST', '127.0.0.1'), + 'port' => env('MEMCACHED_PORT', 11211), + 'weight' => 100, + ], + ], + ], + + 'redis' => [ + 'driver' => 'redis', + 'connection' => 'cache', + 'lock_connection' => 'default', + ], + + 'dynamodb' => [ + 'driver' => 'dynamodb', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), + 'endpoint' => env('DYNAMODB_ENDPOINT'), + ], + + 'octane' => [ + 'driver' => 'octane', + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Cache Key Prefix + |-------------------------------------------------------------------------- + | + | When utilizing the APC, database, memcached, Redis, or DynamoDB cache + | stores there might be other applications using the same cache. For + | that reason, you may prefix every cache key to avoid collisions. + | + */ + + 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'), + +]; diff --git a/config/cors.php b/config/cors.php new file mode 100644 index 0000000..df4ef51 --- /dev/null +++ b/config/cors.php @@ -0,0 +1,36 @@ + ['*'], + + 'allowed_methods' => ['*'], + + 'allowed_origins' => [env('FRONTEND_URL', 'http://localhost:3000')], + + 'allowed_origins_patterns' => [], + + 'allowed_headers' => ['*'], + + 'exposed_headers' => [], + + 'max_age' => 0, + + 'supports_credentials' => true, + +]; diff --git a/config/database.php b/config/database.php new file mode 100644 index 0000000..f75f0d9 --- /dev/null +++ b/config/database.php @@ -0,0 +1,153 @@ + env('DB_CONNECTION', 'mysql'), + + /* + |-------------------------------------------------------------------------- + | Database Connections + |-------------------------------------------------------------------------- + | + | Here are each of the database connections setup for your application. + | Of course, examples of configuring each database platform that is + | supported by Laravel is shown below to make development simple. + | + | + | All database work in Laravel is done through the PHP PDO facilities + | so make sure you have the driver for your particular database of + | choice installed on your machine before you begin development. + | + */ + + 'connections' => [ + + 'sqlite' => [ + 'driver' => 'sqlite', + 'url' => env('DATABASE_URL'), + 'database' => env('DB_DATABASE', database_path('database.sqlite')), + 'prefix' => '', + 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), + ], + + 'mysql' => [ + 'driver' => 'mysql', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => true, + 'engine' => null, + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [], + ], + + 'pgsql' => [ + 'driver' => 'pgsql', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '5432'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => 'utf8', + 'prefix' => '', + 'prefix_indexes' => true, + 'search_path' => 'public', + 'sslmode' => 'prefer', + ], + + 'sqlsrv' => [ + 'driver' => 'sqlsrv', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', '1433'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => 'utf8', + 'prefix' => '', + 'prefix_indexes' => true, + // 'encrypt' => env('DB_ENCRYPT', 'yes'), + // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Migration Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the migrations that have already run for + | your application. Using this information, we can determine which of + | the migrations on disk haven't actually been run in the database. + | + */ + + 'migrations' => 'migrations', + + /* + |-------------------------------------------------------------------------- + | Redis Databases + |-------------------------------------------------------------------------- + | + | Redis is an open source, fast, and advanced key-value store that also + | provides a richer body of commands than a typical key-value system + | such as APC or Memcached. Laravel makes it easy to dig right in. + | + */ + + 'redis' => [ + + 'client' => env('REDIS_CLIENT', 'phpredis'), + + 'options' => [ + 'cluster' => env('REDIS_CLUSTER', 'redis'), + 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), + ], + + 'default' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'username' => env('REDIS_USERNAME'), + 'password' => env('REDIS_PASSWORD'), + 'port' => env('REDIS_PORT', '6379'), + 'database' => env('REDIS_DB', '0'), + ], + + 'cache' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'username' => env('REDIS_USERNAME'), + 'password' => env('REDIS_PASSWORD'), + 'port' => env('REDIS_PORT', '6379'), + 'database' => env('REDIS_CACHE_DB', '1'), + ], + + ], + +]; diff --git a/config/filesystems.php b/config/filesystems.php new file mode 100644 index 0000000..d307268 --- /dev/null +++ b/config/filesystems.php @@ -0,0 +1,78 @@ + env('FILESYSTEM_DISK', 'local'), + + /* + |-------------------------------------------------------------------------- + | Filesystem Disks + |-------------------------------------------------------------------------- + | + | Here you may configure as many filesystem "disks" as you wish, and you + | may even configure multiple disks of the same driver. Defaults have + | been set up for each driver as an example of the required values. + | + | Supported Drivers: "local", "ftp", "sftp", "s3" + | + */ + + 'disks' => [ + + 'local' => [ + 'driver' => 'local', + 'root' => storage_path('app'), + 'throw' => false, + ], + + 'public' => [ + 'driver' => 'local', + 'root' => storage_path('app/public'), + 'url' => env('APP_URL').'/storage', + 'visibility' => 'public', + 'throw' => false, + ], + + 's3' => [ + 'driver' => 's3', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('AWS_DEFAULT_REGION'), + 'bucket' => env('AWS_BUCKET'), + 'url' => env('AWS_URL'), + 'endpoint' => env('AWS_ENDPOINT'), + 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), + 'throw' => false, + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Symbolic Links + |-------------------------------------------------------------------------- + | + | Here you may configure the symbolic links that will be created when the + | `storage:link` Artisan command is executed. The array keys should be + | the locations of the links and the values should be their targets. + | + */ + + 'links' => [ + public_path('storage') => storage_path('app/public'), + ], + +]; diff --git a/config/hashing.php b/config/hashing.php new file mode 100644 index 0000000..41cba61 --- /dev/null +++ b/config/hashing.php @@ -0,0 +1,54 @@ + 'bcrypt', + + /* + |-------------------------------------------------------------------------- + | Bcrypt Options + |-------------------------------------------------------------------------- + | + | Here you may specify the configuration options that should be used when + | passwords are hashed using the Bcrypt algorithm. This will allow you + | to control the amount of time it takes to hash the given password. + | + */ + + 'bcrypt' => [ + 'rounds' => env('BCRYPT_ROUNDS', 10), + ], + + /* + |-------------------------------------------------------------------------- + | Argon Options + |-------------------------------------------------------------------------- + | + | Here you may specify the configuration options that should be used when + | passwords are hashed using the Argon algorithm. These will allow you + | to control the amount of time it takes to hash the given password. + | + */ + + 'argon' => [ + 'memory' => 65536, + 'threads' => 1, + 'time' => 4, + ], + +]; diff --git a/config/headers.php b/config/headers.php new file mode 100644 index 0000000..f6a5a69 --- /dev/null +++ b/config/headers.php @@ -0,0 +1,22 @@ + [ + 'X-Powered-By', + 'x-powered-by', + 'Server', + 'server', + ], + + 'referrer-policy' => 'no-referrer-when-downgrade', + + 'strict-transport-security' => 'max-age=31536000; includeSubDomains', + + 'certificate-transparency' => 'enforce, max-age=30', + + 'permissions-policy' => 'autoplay=(self), camera=(), encrypted-media=(self), fullscreen=(), geolocation=(self), gyroscope=(self), magnetometer=(), microphone=(), midi=(), payment=(), sync-xhr=(self), usb=()', + + 'content-type-options' => 'nosniff', +]; diff --git a/config/logging.php b/config/logging.php new file mode 100644 index 0000000..e20f363 --- /dev/null +++ b/config/logging.php @@ -0,0 +1,125 @@ + env('LOG_CHANNEL', 'stack'), + + /* + |-------------------------------------------------------------------------- + | Deprecations Log Channel + |-------------------------------------------------------------------------- + | + | This option controls the log channel that should be used to log warnings + | regarding deprecated PHP and library features. This allows you to get + | your application ready for upcoming major versions of dependencies. + | + */ + + 'deprecations' => [ + 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), + 'trace' => false, + ], + + /* + |-------------------------------------------------------------------------- + | Log Channels + |-------------------------------------------------------------------------- + | + | Here you may configure the log channels for your application. Out of + | the box, Laravel uses the Monolog PHP logging library. This gives + | you a variety of powerful log handlers / formatters to utilize. + | + | Available Drivers: "single", "daily", "slack", "syslog", + | "errorlog", "monolog", + | "custom", "stack" + | + */ + + 'channels' => [ + 'stack' => [ + 'driver' => 'stack', + 'channels' => ['single'], + 'ignore_exceptions' => false, + ], + + 'single' => [ + 'driver' => 'single', + 'path' => storage_path('logs/laravel.log'), + 'level' => env('LOG_LEVEL', 'debug'), + ], + + 'daily' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/laravel.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'days' => 14, + ], + + 'slack' => [ + 'driver' => 'slack', + 'url' => env('LOG_SLACK_WEBHOOK_URL'), + 'username' => 'Laravel Log', + 'emoji' => ':boom:', + 'level' => env('LOG_LEVEL', 'critical'), + ], + + 'papertrail' => [ + 'driver' => 'monolog', + 'level' => env('LOG_LEVEL', 'debug'), + 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), + 'handler_with' => [ + 'host' => env('PAPERTRAIL_URL'), + 'port' => env('PAPERTRAIL_PORT'), + 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), + ], + ], + + 'stderr' => [ + 'driver' => 'monolog', + 'level' => env('LOG_LEVEL', 'debug'), + 'handler' => StreamHandler::class, + 'formatter' => env('LOG_STDERR_FORMATTER'), + 'with' => [ + 'stream' => 'php://stderr', + ], + ], + + 'syslog' => [ + 'driver' => 'syslog', + 'level' => env('LOG_LEVEL', 'debug'), + 'facility' => LOG_USER, + ], + + 'errorlog' => [ + 'driver' => 'errorlog', + 'level' => env('LOG_LEVEL', 'debug'), + ], + + 'null' => [ + 'driver' => 'monolog', + 'handler' => NullHandler::class, + ], + + 'emergency' => [ + 'path' => storage_path('logs/laravel.log'), + ], + ], + +]; diff --git a/config/mail.php b/config/mail.php new file mode 100644 index 0000000..1cb9684 --- /dev/null +++ b/config/mail.php @@ -0,0 +1,126 @@ + env('MAIL_MAILER', 'smtp'), + + /* + |-------------------------------------------------------------------------- + | Mailer Configurations + |-------------------------------------------------------------------------- + | + | Here you may configure all of the mailers used by your application plus + | their respective settings. Several examples have been configured for + | you and you are free to add your own as your application requires. + | + | Laravel supports a variety of mail "transport" drivers to be used while + | sending an e-mail. You will specify which one you are using for your + | mailers below. You are free to add additional mailers as required. + | + | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", + | "postmark", "log", "array", "failover" + | + */ + + 'mailers' => [ + 'smtp' => [ + 'transport' => 'smtp', + 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), + 'port' => env('MAIL_PORT', 587), + 'encryption' => env('MAIL_ENCRYPTION', 'tls'), + 'username' => env('MAIL_USERNAME'), + 'password' => env('MAIL_PASSWORD'), + 'timeout' => null, + 'local_domain' => env('MAIL_EHLO_DOMAIN'), + ], + + 'ses' => [ + 'transport' => 'ses', + ], + + 'mailgun' => [ + 'transport' => 'mailgun', + // 'client' => [ + // 'timeout' => 5, + // ], + ], + + 'postmark' => [ + 'transport' => 'postmark', + // 'client' => [ + // 'timeout' => 5, + // ], + ], + + 'sendmail' => [ + 'transport' => 'sendmail', + 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), + ], + + 'log' => [ + 'transport' => 'log', + 'channel' => env('MAIL_LOG_CHANNEL'), + ], + + 'array' => [ + 'transport' => 'array', + ], + + 'failover' => [ + 'transport' => 'failover', + 'mailers' => [ + 'smtp', + 'log', + ], + ], + ], + + /* + |-------------------------------------------------------------------------- + | Global "From" Address + |-------------------------------------------------------------------------- + | + | You may wish for all e-mails sent by your application to be sent from + | the same address. Here, you may specify a name and address that is + | used globally for all e-mails that are sent by your application. + | + */ + + 'from' => [ + 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), + 'name' => env('MAIL_FROM_NAME', 'Example'), + ], + + /* + |-------------------------------------------------------------------------- + | Markdown Mail Settings + |-------------------------------------------------------------------------- + | + | If you are using Markdown based email rendering, you may configure your + | theme and component paths here, allowing you to customize the design + | of the emails. Or, you may simply stick with the Laravel defaults! + | + */ + + 'markdown' => [ + 'theme' => 'default', + + 'paths' => [ + resource_path('views/vendor/mail'), + ], + ], + +]; diff --git a/config/queue.php b/config/queue.php new file mode 100644 index 0000000..485dd98 --- /dev/null +++ b/config/queue.php @@ -0,0 +1,95 @@ + env('QUEUE_CONNECTION', 'sync'), + + /* + |-------------------------------------------------------------------------- + | Queue Connections + |-------------------------------------------------------------------------- + | + | Here you may configure the connection information for each server that + | is used by your application. A default configuration has been added + | for each back-end shipped with Laravel. You are free to add more. + | + | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" + | + */ + + 'connections' => [ + + 'sync' => [ + 'driver' => 'sync', + ], + + 'database' => [ + 'driver' => 'database', + 'table' => 'jobs', + 'queue' => 'default', + 'retry_after' => 90, + 'after_commit' => false, + ], + + 'beanstalkd' => [ + 'driver' => 'beanstalkd', + 'host' => 'localhost', + 'queue' => 'default', + 'retry_after' => 90, + 'block_for' => 0, + 'after_commit' => false, + ], + + 'sqs' => [ + 'driver' => 'sqs', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), + 'queue' => env('SQS_QUEUE', 'default'), + 'suffix' => env('SQS_SUFFIX'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + 'after_commit' => false, + ], + + 'redis' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => env('REDIS_QUEUE', 'default'), + 'retry_after' => 90, + 'block_for' => null, + 'after_commit' => false, + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Failed Queue Jobs + |-------------------------------------------------------------------------- + | + | These options configure the behavior of failed queue job logging so you + | can control which database and table are used to store the jobs that + | have failed. You may change them to any database / table you wish. + | + */ + + 'failed' => [ + 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), + 'database' => env('DB_CONNECTION', 'mysql'), + 'table' => 'failed_jobs', + ], + +]; diff --git a/config/sanctum.php b/config/sanctum.php new file mode 100644 index 0000000..7f38290 --- /dev/null +++ b/config/sanctum.php @@ -0,0 +1,54 @@ + explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( + '%s%s%s', + 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', + env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : '', + env('FRONTEND_URL') ? ','.parse_url(env('FRONTEND_URL'), PHP_URL_HOST) : '' + ))), + + /* + |-------------------------------------------------------------------------- + | Expiration Minutes + |-------------------------------------------------------------------------- + | + | This value controls the number of minutes until an issued token will be + | considered expired. If this value is null, personal access tokens do + | not expire. This won't tweak the lifetime of first-party sessions. + | + */ + + 'expiration' => null, + + /* + |-------------------------------------------------------------------------- + | Sanctum Middleware + |-------------------------------------------------------------------------- + | + | When authenticating your first-party SPA with Sanctum you may need to + | customize some of the middleware Sanctum uses while processing the + | request. You may change the middleware listed below as required. + | + */ + + 'middleware' => [ + 'verify_csrf_token' => \Core\Http\Middleware\VerifyCsrfToken::class, + 'encrypt_cookies' => \Core\Http\Middleware\EncryptCookies::class, + ], + +]; diff --git a/config/services.php b/config/services.php new file mode 100644 index 0000000..104826f --- /dev/null +++ b/config/services.php @@ -0,0 +1,36 @@ + [ + 'domain' => env('MAILGUN_DOMAIN'), + 'secret' => env('MAILGUN_SECRET'), + 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), + 'scheme' => 'https', + ], + + 'postmark' => [ + 'token' => env('POSTMARK_TOKEN'), + ], + + 'ses' => [ + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + ], + +]; diff --git a/config/session.php b/config/session.php new file mode 100644 index 0000000..eeee93d --- /dev/null +++ b/config/session.php @@ -0,0 +1,203 @@ + env('SESSION_DRIVER', 'file'), + + /* + |-------------------------------------------------------------------------- + | Session Lifetime + |-------------------------------------------------------------------------- + | + | Here you may specify the number of minutes that you wish the session + | to be allowed to remain idle before it expires. If you want them + | to immediately expire on the browser closing, set that option. + | + */ + + 'lifetime' => env('SESSION_LIFETIME', 120), + + 'expire_on_close' => false, + + /* + |-------------------------------------------------------------------------- + | Session Encryption + |-------------------------------------------------------------------------- + | + | This option allows you to easily specify that all of your session data + | should be encrypted before it is stored. All encryption will be run + | automatically by Laravel and you can use the Session like normal. + | + */ + + 'encrypt' => false, + + /* + |-------------------------------------------------------------------------- + | Session File Location + |-------------------------------------------------------------------------- + | + | When using the native session driver, we need a location where session + | files may be stored. A default has been set for you but a different + | location may be specified. This is only needed for file sessions. + | + */ + + 'files' => storage_path('framework/sessions'), + + /* + |-------------------------------------------------------------------------- + | Session Database Connection + |-------------------------------------------------------------------------- + | + | When using the "database" or "redis" session drivers, you may specify a + | connection that should be used to manage these sessions. This should + | correspond to a connection in your database configuration options. + | + */ + + 'connection' => env('SESSION_CONNECTION'), + + /* + |-------------------------------------------------------------------------- + | Session Database Table + |-------------------------------------------------------------------------- + | + | When using the "database" session driver, you may specify the table we + | should use to manage the sessions. Of course, a sensible default is + | provided for you; however, you are free to change this as needed. + | + */ + + 'table' => 'sessions', + + /* + |-------------------------------------------------------------------------- + | Session Cache Store + |-------------------------------------------------------------------------- + | + | While using one of the framework's cache driven session backends you may + | list a cache store that should be used for these sessions. This value + | must match with one of the application's configured cache "stores". + | + | Affects: "apc", "dynamodb", "memcached", "redis" + | + */ + + 'store' => env('SESSION_STORE'), + + /* + |-------------------------------------------------------------------------- + | Session Sweeping Lottery + |-------------------------------------------------------------------------- + | + | Some session drivers must manually sweep their storage location to get + | rid of old sessions from storage. Here are the chances that it will + | happen on a given request. By default, the odds are 2 out of 100. + | + */ + + 'lottery' => [2, 100], + + /* + |-------------------------------------------------------------------------- + | Session Cookie Name + |-------------------------------------------------------------------------- + | + | Here you may change the name of the cookie used to identify a session + | instance by ID. The name specified here will get used every time a + | new session cookie is created by the framework for every driver. + | + */ + + 'cookie' => env( + 'SESSION_COOKIE', + Str::slug(env('APP_NAME', 'laravel'), '_').'_session' + ), + + /* + |-------------------------------------------------------------------------- + | Session Cookie Path + |-------------------------------------------------------------------------- + | + | The session cookie path determines the path for which the cookie will + | be regarded as available. Typically, this will be the root path of + | your application but you are free to change this when necessary. + | + */ + + 'path' => '/', + + /* + |-------------------------------------------------------------------------- + | Session Cookie Domain + |-------------------------------------------------------------------------- + | + | Here you may change the domain of the cookie used to identify a session + | in your application. This will determine which domains the cookie is + | available to in your application. A sensible default has been set. + | + */ + + 'domain' => env('SESSION_DOMAIN'), + + /* + |-------------------------------------------------------------------------- + | HTTPS Only Cookies + |-------------------------------------------------------------------------- + | + | By setting this option to true, session cookies will only be sent back + | to the server if the browser has a HTTPS connection. This will keep + | the cookie from being sent to you when it can't be done securely. + | + */ + + 'secure' => env('SESSION_SECURE_COOKIE'), + + /* + |-------------------------------------------------------------------------- + | HTTP Access Only + |-------------------------------------------------------------------------- + | + | Setting this value to true will prevent JavaScript from accessing the + | value of the cookie and the cookie will only be accessible through + | the HTTP protocol. You are free to modify this option if needed. + | + */ + + 'http_only' => true, + + /* + |-------------------------------------------------------------------------- + | Same-Site Cookies + |-------------------------------------------------------------------------- + | + | This option determines how your cookies behave when cross-site requests + | take place, and can be used to mitigate CSRF attacks. By default, we + | will set this value to "lax" since this is a secure default value. + | + | Supported: "lax", "strict", "none", null + | + */ + + 'same_site' => 'lax', + +]; diff --git a/config/treblle.php b/config/treblle.php new file mode 100644 index 0000000..7f6f900 --- /dev/null +++ b/config/treblle.php @@ -0,0 +1,36 @@ + env('TREBLLE_API_KEY'), + + /* + * A valid Treblle project ID. Create your first project on https://treblle.com/ + */ + 'project_id' => env('TREBLLE_PROJECT_ID'), + + /* + * Define which environments should Treblle ignore and not monitor + */ + 'ignored_environments' => env('TREBLLE_IGNORED_ENV', 'dev,test'), + + /* + * Define which fields should be masked before leaving the server + */ + 'masked_fields' => [ + 'password', + 'pwd', + 'secret', + 'password_confirmation', + 'cc', + 'card_number', + 'ccv', + 'ssn', + 'credit_score', + 'api_key', + ], +]; diff --git a/config/view.php b/config/view.php new file mode 100644 index 0000000..d9c90c0 --- /dev/null +++ b/config/view.php @@ -0,0 +1,38 @@ + [ + resource_path('views'), + ], + + /* + |-------------------------------------------------------------------------- + | Compiled View Path + |-------------------------------------------------------------------------- + | + | This option determines where all the compiled Blade templates will be + | stored for your application. Typically, this is within the storage + | directory. However, as usual, you are free to change this value. + | + */ + + 'compiled' => env( + 'VIEW_COMPILED_PATH', + realpath(storage_path('framework/views')) + ), + +]; diff --git a/core/Console/Kernel.php b/core/Console/Kernel.php new file mode 100644 index 0000000..09b7548 --- /dev/null +++ b/core/Console/Kernel.php @@ -0,0 +1,25 @@ +load( + paths: [ + __DIR__ . '/../app/Console/Commands', + ], + ); + } +} diff --git a/core/Exceptions/Handler.php b/core/Exceptions/Handler.php new file mode 100644 index 0000000..2be409d --- /dev/null +++ b/core/Exceptions/Handler.php @@ -0,0 +1,28 @@ +reportable(function (Throwable $e) { + // + }); + } +} diff --git a/core/Http/Controllers/Controller.php b/core/Http/Controllers/Controller.php new file mode 100644 index 0000000..375b591 --- /dev/null +++ b/core/Http/Controllers/Controller.php @@ -0,0 +1,15 @@ + [], + + 'api' => [ + ThrottleRequests::class.':api', + ContentTypeMiddleware::class, + CacheHeaders::class, + RemoveHeaders::class, + StrictTransportSecurity::class, + SetReferrerPolicy::class, + PermissionsPolicy::class, + ContentTypeOptions::class, + CertificateTransparencyPolicy::class, + XFrameOptionMiddleware::class, + ], + ]; + + protected $middlewareAliases = [ + 'auth' => Authenticate::class, + 'cache.headers' => SetCacheHeaders::class, + 'can' => Authorize::class, + 'password.confirm' => RequirePassword::class, + 'signed' => ValidateSignature::class, + 'throttle' => ThrottleRequests::class, + 'verified' => EnsureEmailIsVerified::class, + ]; +} diff --git a/core/Providers/AppServiceProvider.php b/core/Providers/AppServiceProvider.php new file mode 100644 index 0000000..8f74df1 --- /dev/null +++ b/core/Providers/AppServiceProvider.php @@ -0,0 +1,15 @@ +registerPolicies(); + } +} diff --git a/core/Providers/BroadcastServiceProvider.php b/core/Providers/BroadcastServiceProvider.php new file mode 100644 index 0000000..f379f20 --- /dev/null +++ b/core/Providers/BroadcastServiceProvider.php @@ -0,0 +1,17 @@ + [ + SendEmailVerificationNotification::class, + ], + ]; +} diff --git a/core/Providers/RouteServiceProvider.php b/core/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..85312e2 --- /dev/null +++ b/core/Providers/RouteServiceProvider.php @@ -0,0 +1,39 @@ +configureRateLimiting(); + + $this->routes(static function (): void { + Route::middleware('api') + ->as('api:') + ->group( + base_path('routes/api/routes.php') + ); + }); + } + + protected function configureRateLimiting(): void + { + RateLimiter::for( + name: 'api', + callback: static fn (Request $request): Limit => Limit::perMinute( + maxAttempts: 60, + )->by( + key: $request->user()?->id ?: $request->ip(), + ), + ); + } +} diff --git a/database/.gitignore b/database/.gitignore new file mode 100644 index 0000000..9b19b93 --- /dev/null +++ b/database/.gitignore @@ -0,0 +1 @@ +*.sqlite* diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 0000000..75fc148 --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,35 @@ + $this->faker->name(), + 'email' => $this->faker->unique()->safeEmail(), + 'email_verified_at' => now(), + 'password' => Hash::make( + value: 'password', + ), + ]; + } + + public function unverified(): UserFactory + { + return $this->state( + state: fn (array $attributes): array => [ + 'email_verified_at' => null, + ], + ); + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php new file mode 100644 index 0000000..dd9c0a1 --- /dev/null +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -0,0 +1,28 @@ +ulid('id')->primary(); + + $table->string('name'); + $table->string('email')->unique(); + $table->string('password'); + + $table->timestamp('email_verified_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('users'); + } +}; diff --git a/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php b/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php new file mode 100644 index 0000000..f9d43b1 --- /dev/null +++ b/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php @@ -0,0 +1,23 @@ +string('email')->primary(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + }); + } + + public function down(): void + { + Schema::dropIfExists('password_reset_tokens'); + } +}; diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php new file mode 100644 index 0000000..4af0906 --- /dev/null +++ b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -0,0 +1,27 @@ +id(); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + public function down(): void + { + Schema::dropIfExists('failed_jobs'); + } +}; diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php new file mode 100644 index 0000000..6795f42 --- /dev/null +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -0,0 +1,30 @@ +id(); + + $table->ulidMorphs('tokenable'); + $table->string('name'); + $table->string('token', 64)->unique(); + $table->text('abilities')->nullable(); + + $table->timestamp('last_used_at')->nullable(); + $table->timestamp('expires_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('personal_access_tokens'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php new file mode 100644 index 0000000..985b5b7 --- /dev/null +++ b/database/seeders/DatabaseSeeder.php @@ -0,0 +1,19 @@ +create([ + 'name' => 'Arthur Monney', + 'email' => 'monneylobe@gmail.com', + ]); + } +} diff --git a/lang/en/auth.php b/lang/en/auth.php new file mode 100644 index 0000000..e2de2ac --- /dev/null +++ b/lang/en/auth.php @@ -0,0 +1,22 @@ + 'These credentials do not match our records.', + 'password' => 'The provided password is incorrect.', + 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', + +]; diff --git a/lang/en/messages.php b/lang/en/messages.php new file mode 100644 index 0000000..376c7e3 --- /dev/null +++ b/lang/en/messages.php @@ -0,0 +1,9 @@ + 'Welcome to Laravel API Skeleton', + +]; diff --git a/lang/en/pagination.php b/lang/en/pagination.php new file mode 100644 index 0000000..f03c42c --- /dev/null +++ b/lang/en/pagination.php @@ -0,0 +1,21 @@ + '« Previous', + 'next' => 'Next »', + +]; diff --git a/lang/en/passwords.php b/lang/en/passwords.php new file mode 100644 index 0000000..4309232 --- /dev/null +++ b/lang/en/passwords.php @@ -0,0 +1,24 @@ + 'Your password has been reset.', + 'sent' => 'We have emailed your password reset link.', + 'throttled' => 'Please wait before retrying.', + 'token' => 'This password reset token is invalid.', + 'user' => "We can't find a user with that email address.", + +]; diff --git a/lang/en/validation.php b/lang/en/validation.php new file mode 100644 index 0000000..fd0ec4b --- /dev/null +++ b/lang/en/validation.php @@ -0,0 +1,186 @@ + 'The :attribute field must be accepted.', + 'accepted_if' => 'The :attribute field must be accepted when :other is :value.', + 'active_url' => 'The :attribute field must be a valid URL.', + 'after' => 'The :attribute field must be a date after :date.', + 'after_or_equal' => 'The :attribute field must be a date after or equal to :date.', + 'alpha' => 'The :attribute field must only contain letters.', + 'alpha_dash' => 'The :attribute field must only contain letters, numbers, dashes, and underscores.', + 'alpha_num' => 'The :attribute field must only contain letters and numbers.', + 'array' => 'The :attribute field must be an array.', + 'ascii' => 'The :attribute field must only contain single-byte alphanumeric characters and symbols.', + 'before' => 'The :attribute field must be a date before :date.', + 'before_or_equal' => 'The :attribute field must be a date before or equal to :date.', + 'between' => [ + 'array' => 'The :attribute field must have between :min and :max items.', + 'file' => 'The :attribute field must be between :min and :max kilobytes.', + 'numeric' => 'The :attribute field must be between :min and :max.', + 'string' => 'The :attribute field must be between :min and :max characters.', + ], + 'boolean' => 'The :attribute field must be true or false.', + 'confirmed' => 'The :attribute field confirmation does not match.', + 'current_password' => 'The password is incorrect.', + 'date' => 'The :attribute field must be a valid date.', + 'date_equals' => 'The :attribute field must be a date equal to :date.', + 'date_format' => 'The :attribute field must match the format :format.', + 'decimal' => 'The :attribute field must have :decimal decimal places.', + 'declined' => 'The :attribute field must be declined.', + 'declined_if' => 'The :attribute field must be declined when :other is :value.', + 'different' => 'The :attribute field and :other must be different.', + 'digits' => 'The :attribute field must be :digits digits.', + 'digits_between' => 'The :attribute field must be between :min and :max digits.', + 'dimensions' => 'The :attribute field has invalid image dimensions.', + 'distinct' => 'The :attribute field has a duplicate value.', + 'doesnt_end_with' => 'The :attribute field must not end with one of the following: :values.', + 'doesnt_start_with' => 'The :attribute field must not start with one of the following: :values.', + 'email' => 'The :attribute field must be a valid email address.', + 'ends_with' => 'The :attribute field must end with one of the following: :values.', + 'enum' => 'The selected :attribute is invalid.', + 'exists' => 'The selected :attribute is invalid.', + 'file' => 'The :attribute field must be a file.', + 'filled' => 'The :attribute field must have a value.', + 'gt' => [ + 'array' => 'The :attribute field must have more than :value items.', + 'file' => 'The :attribute field must be greater than :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than :value.', + 'string' => 'The :attribute field must be greater than :value characters.', + ], + 'gte' => [ + 'array' => 'The :attribute field must have :value items or more.', + 'file' => 'The :attribute field must be greater than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than or equal to :value.', + 'string' => 'The :attribute field must be greater than or equal to :value characters.', + ], + 'image' => 'The :attribute field must be an image.', + 'in' => 'The selected :attribute is invalid.', + 'in_array' => 'The :attribute field must exist in :other.', + 'integer' => 'The :attribute field must be an integer.', + 'ip' => 'The :attribute field must be a valid IP address.', + 'ipv4' => 'The :attribute field must be a valid IPv4 address.', + 'ipv6' => 'The :attribute field must be a valid IPv6 address.', + 'json' => 'The :attribute field must be a valid JSON string.', + 'lowercase' => 'The :attribute field must be lowercase.', + 'lt' => [ + 'array' => 'The :attribute field must have less than :value items.', + 'file' => 'The :attribute field must be less than :value kilobytes.', + 'numeric' => 'The :attribute field must be less than :value.', + 'string' => 'The :attribute field must be less than :value characters.', + ], + 'lte' => [ + 'array' => 'The :attribute field must not have more than :value items.', + 'file' => 'The :attribute field must be less than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be less than or equal to :value.', + 'string' => 'The :attribute field must be less than or equal to :value characters.', + ], + 'mac_address' => 'The :attribute field must be a valid MAC address.', + 'max' => [ + 'array' => 'The :attribute field must not have more than :max items.', + 'file' => 'The :attribute field must not be greater than :max kilobytes.', + 'numeric' => 'The :attribute field must not be greater than :max.', + 'string' => 'The :attribute field must not be greater than :max characters.', + ], + 'max_digits' => 'The :attribute field must not have more than :max digits.', + 'mimes' => 'The :attribute field must be a file of type: :values.', + 'mimetypes' => 'The :attribute field must be a file of type: :values.', + 'min' => [ + 'array' => 'The :attribute field must have at least :min items.', + 'file' => 'The :attribute field must be at least :min kilobytes.', + 'numeric' => 'The :attribute field must be at least :min.', + 'string' => 'The :attribute field must be at least :min characters.', + ], + 'min_digits' => 'The :attribute field must have at least :min digits.', + 'missing' => 'The :attribute field must be missing.', + 'missing_if' => 'The :attribute field must be missing when :other is :value.', + 'missing_unless' => 'The :attribute field must be missing unless :other is :value.', + 'missing_with' => 'The :attribute field must be missing when :values is present.', + 'missing_with_all' => 'The :attribute field must be missing when :values are present.', + 'multiple_of' => 'The :attribute field must be a multiple of :value.', + 'not_in' => 'The selected :attribute is invalid.', + 'not_regex' => 'The :attribute field format is invalid.', + 'numeric' => 'The :attribute field must be a number.', + 'password' => [ + 'letters' => 'The :attribute field must contain at least one letter.', + 'mixed' => 'The :attribute field must contain at least one uppercase and one lowercase letter.', + 'numbers' => 'The :attribute field must contain at least one number.', + 'symbols' => 'The :attribute field must contain at least one symbol.', + 'uncompromised' => 'The given :attribute has appeared in a data leak. Please choose a different :attribute.', + ], + 'present' => 'The :attribute field must be present.', + 'prohibited' => 'The :attribute field is prohibited.', + 'prohibited_if' => 'The :attribute field is prohibited when :other is :value.', + 'prohibited_unless' => 'The :attribute field is prohibited unless :other is in :values.', + 'prohibits' => 'The :attribute field prohibits :other from being present.', + 'regex' => 'The :attribute field format is invalid.', + 'required' => 'The :attribute field is required.', + 'required_array_keys' => 'The :attribute field must contain entries for: :values.', + 'required_if' => 'The :attribute field is required when :other is :value.', + 'required_if_accepted' => 'The :attribute field is required when :other is accepted.', + 'required_unless' => 'The :attribute field is required unless :other is in :values.', + 'required_with' => 'The :attribute field is required when :values is present.', + 'required_with_all' => 'The :attribute field is required when :values are present.', + 'required_without' => 'The :attribute field is required when :values is not present.', + 'required_without_all' => 'The :attribute field is required when none of :values are present.', + 'same' => 'The :attribute field must match :other.', + 'size' => [ + 'array' => 'The :attribute field must contain :size items.', + 'file' => 'The :attribute field must be :size kilobytes.', + 'numeric' => 'The :attribute field must be :size.', + 'string' => 'The :attribute field must be :size characters.', + ], + 'starts_with' => 'The :attribute field must start with one of the following: :values.', + 'string' => 'The :attribute field must be a string.', + 'timezone' => 'The :attribute field must be a valid timezone.', + 'unique' => 'The :attribute has already been taken.', + 'uploaded' => 'The :attribute failed to upload.', + 'uppercase' => 'The :attribute field must be uppercase.', + 'url' => 'The :attribute field must be a valid URL.', + 'ulid' => 'The :attribute field must be a valid ULID.', + 'uuid' => 'The :attribute field must be a valid UUID.', + + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap our attribute placeholder + | with something more reader friendly such as "E-Mail Address" instead + | of "email". This simply helps us make our message more expressive. + | + */ + + 'attributes' => [], + +]; diff --git a/lang/fr/messages.php b/lang/fr/messages.php new file mode 100644 index 0000000..5710fca --- /dev/null +++ b/lang/fr/messages.php @@ -0,0 +1,9 @@ + 'Bienvenue sur Laravel API Skeleton', + +]; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..c0cb389 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,21 @@ + +includes: + - ./vendor/nunomaduro/larastan/extension.neon + +parameters: + + paths: + - .core/ + - app/ + + level: 9 + + ignoreErrors: + + excludePaths: + - app/Http/Controllers/Auth/ + - app/Http/Middleware/ + - app/Http/Requests/Auth + - app/Providers/AuthServiceProvider.php + + checkMissingIterableValueType: false diff --git a/phpunit.xml b/phpunit.xml index c195e86..59b58db 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,22 +1,31 @@ - - - ./skeleton/tests - ./tests/scaffolds + + ./tests/Unit + + + ./tests/Feature + + + ./app + + + + + + + + + + + + diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..bd6ec48 --- /dev/null +++ b/pint.json @@ -0,0 +1,42 @@ +{ + "preset": "psr12", + "rules": { + "align_multiline_comment": true, + "array_indentation": true, + "array_syntax": true, + "blank_line_after_namespace": true, + "blank_line_after_opening_tag": true, + "combine_consecutive_issets": true, + "combine_consecutive_unsets": true, + "concat_space": true, + "declare_parentheses": true, + "declare_strict_types": true, + "explicit_string_variable": true, + "final_class": true, + "final_internal_class": false, + "fully_qualified_strict_types": true, + "global_namespace_import": { + "import_classes": true, + "import_constants": true, + "import_functions": true + }, + "is_null": true, + "lambda_not_used_import": true, + "logical_operators": true, + "mb_str_functions": true, + "method_chaining_indentation": true, + "modernize_strpos": true, + "new_with_braces": true, + "no_empty_comment": true, + "not_operator_with_space": true, + "ordered_traits": true, + "protected_to_private": true, + "simplified_if_return": true, + "strict_comparison": true, + "ternary_to_null_coalescing": true, + "trim_array_spaces": true, + "use_arrow_functions": true, + "void_return": true, + "yoda_style": true + } +} diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..3aec5e2 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,21 @@ + + + Options -MultiViews -Indexes + + + RewriteEngine On + + # Handle Authorization Header + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + # Redirect Trailing Slashes If Not A Folder... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_URI} (.+)/$ + RewriteRule ^ %1 [L,R=301] + + # Send Requests To Front Controller... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [L] + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..0765415 --- /dev/null +++ b/public/index.php @@ -0,0 +1,57 @@ +make(Kernel::class); + +$response = $kernel->handle( + $request = Request::capture() +)->send(); + +$kernel->terminate($request, $response); diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/resources/views/.gitkeep b/resources/views/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/resources/views/.gitkeep @@ -0,0 +1 @@ + diff --git a/routes/api/routes.php b/routes/api/routes.php new file mode 100644 index 0000000..eee66aa --- /dev/null +++ b/routes/api/routes.php @@ -0,0 +1,12 @@ +as('v1:')->group( + base_path('routes/api/v1/api.php'), +); diff --git a/routes/api/v1/api.php b/routes/api/v1/api.php new file mode 100644 index 0000000..f85e293 --- /dev/null +++ b/routes/api/v1/api.php @@ -0,0 +1,7 @@ + ['message' => 'Welcome to the API version 1.0 !'])->name('home'); diff --git a/routes/sockets/routes.php b/routes/sockets/routes.php new file mode 100644 index 0000000..f2635d0 --- /dev/null +++ b/routes/sockets/routes.php @@ -0,0 +1,11 @@ + (int) $user->getKey() === $id +); diff --git a/storage/app/.gitignore b/storage/app/.gitignore new file mode 100644 index 0000000..8f4803c --- /dev/null +++ b/storage/app/.gitignore @@ -0,0 +1,3 @@ +* +!public/ +!.gitignore diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/app/public/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore new file mode 100644 index 0000000..05c4471 --- /dev/null +++ b/storage/framework/.gitignore @@ -0,0 +1,9 @@ +compiled.php +config.php +down +events.scanned.php +maintenance.php +routes.php +routes.scanned.php +schedule-* +services.json diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore new file mode 100644 index 0000000..01e4a6c --- /dev/null +++ b/storage/framework/cache/.gitignore @@ -0,0 +1,3 @@ +* +!data/ +!.gitignore diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/framework/cache/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/framework/sessions/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/storage/framework/testing/.gitignore b/storage/framework/testing/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/framework/testing/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/framework/views/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/storage/logs/.gitignore b/storage/logs/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/logs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/stubs/cast.stub b/stubs/cast.stub new file mode 100644 index 0000000..2a91141 --- /dev/null +++ b/stubs/cast.stub @@ -0,0 +1,31 @@ + $attributes + */ + public function get(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } + + /** + * Prepare the given value for storage. + * + * @param array $attributes + */ + public function set(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } +} diff --git a/stubs/console.stub b/stubs/console.stub new file mode 100644 index 0000000..ccc30e5 --- /dev/null +++ b/stubs/console.stub @@ -0,0 +1,19 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/stubs/factory.stub b/stubs/factory.stub new file mode 100644 index 0000000..b5d39f5 --- /dev/null +++ b/stubs/factory.stub @@ -0,0 +1,19 @@ + + */ + public function via(object $notifiable): array + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + return (new MailMessage)->markdown('{{ view }}'); + } + + /** + * Get the array representation of the notification. + * + * @return array + */ + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +} diff --git a/stubs/middleware.stub b/stubs/middleware.stub new file mode 100644 index 0000000..76b7b53 --- /dev/null +++ b/stubs/middleware.stub @@ -0,0 +1,17 @@ +ulid('id')->primary(); + + // + + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('{{ table }}'); + } +}; diff --git a/stubs/migration.stub b/stubs/migration.stub new file mode 100644 index 0000000..62a5c4a --- /dev/null +++ b/stubs/migration.stub @@ -0,0 +1,20 @@ +line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +} diff --git a/stubs/policy.stub b/stubs/policy.stub new file mode 100644 index 0000000..fbf7535 --- /dev/null +++ b/stubs/policy.stub @@ -0,0 +1,47 @@ + + */ + public function toArray(Request $request): array + { + return parent::toArray($request); + } +} diff --git a/stubs/rule.stub b/stubs/rule.stub new file mode 100644 index 0000000..1028273 --- /dev/null +++ b/stubs/rule.stub @@ -0,0 +1,19 @@ +make(Kernel::class)->bootstrap(); + + return $app; + } +} diff --git a/tests/Feature/Http/Controllers/V1/.gitkeep b/tests/Feature/Http/Controllers/V1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..21f6593 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,11 @@ +in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..5341116 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,12 @@ + Date: Sun, 31 Dec 2023 06:49:01 +0100 Subject: [PATCH 2/8] install passport --- app/Http/Controllers/Controller.php | 15 +++++ app/Http/Controllers/V1/AuthController.php | 36 +++++++++++ app/Http/Requests/Auth/RegisterRequest.php | 24 +++++++ app/Models/User.php | 3 +- config/auth.php | 5 ++ config/passport.php | 62 +++++++++++++++++++ ...1_000001_create_oauth_auth_codes_table.php | 31 ++++++++++ ...00002_create_oauth_access_tokens_table.php | 33 ++++++++++ ...0003_create_oauth_refresh_tokens_table.php | 29 +++++++++ ...6_01_000004_create_oauth_clients_table.php | 35 +++++++++++ ...te_oauth_personal_access_clients_table.php | 28 +++++++++ routes/api/v1/api.php | 6 ++ 12 files changed, 306 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Controller.php create mode 100644 app/Http/Controllers/V1/AuthController.php create mode 100644 app/Http/Requests/Auth/RegisterRequest.php create mode 100644 config/passport.php create mode 100644 database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php create mode 100644 database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php create mode 100644 database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php create mode 100644 database/migrations/2016_06_01_000004_create_oauth_clients_table.php create mode 100644 database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php new file mode 100644 index 0000000..603e8bc --- /dev/null +++ b/app/Http/Controllers/Controller.php @@ -0,0 +1,15 @@ +validated(); + + $data['password'] = bcrypt($request->password); + + $user = User::create($data); + + $token = $user->createToken('AUTHTOKEN')->accessToken; + + return response()->json([ + 'message' => 'Success', + 'user' => $user, + 'token' => $token, + ], Response::HTTP_CREATED); + } + + public function login() + { + + } +} diff --git a/app/Http/Requests/Auth/RegisterRequest.php b/app/Http/Requests/Auth/RegisterRequest.php new file mode 100644 index 0000000..9be9461 --- /dev/null +++ b/app/Http/Requests/Auth/RegisterRequest.php @@ -0,0 +1,24 @@ + 'required|string', + "email" => 'required|email|unique:users,email', + "password" => 'required|string|min:8' + ]; + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 82d89da..948c2cd 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -8,7 +8,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use Laravel\Sanctum\HasApiTokens; +// use Laravel\Sanctum\HasApiTokens; +use Laravel\Passport\HasApiTokens; final class User extends Authenticatable { diff --git a/config/auth.php b/config/auth.php index 3fdb672..217449e 100644 --- a/config/auth.php +++ b/config/auth.php @@ -42,6 +42,11 @@ 'driver' => 'session', 'provider' => 'users', ], + + 'api' => [ + 'driver' => 'passport', + 'provider' => 'users', + ], ], /* diff --git a/config/passport.php b/config/passport.php new file mode 100644 index 0000000..9aa5fe8 --- /dev/null +++ b/config/passport.php @@ -0,0 +1,62 @@ + 'web', + + /* + |-------------------------------------------------------------------------- + | Encryption Keys + |-------------------------------------------------------------------------- + | + | Passport uses encryption keys while generating secure access tokens for + | your application. By default, the keys are stored as local files but + | can be set via environment variables when that is more convenient. + | + */ + + 'private_key' => env('PASSPORT_PRIVATE_KEY'), + + 'public_key' => env('PASSPORT_PUBLIC_KEY'), + + /* + |-------------------------------------------------------------------------- + | Client UUIDs + |-------------------------------------------------------------------------- + | + | By default, Passport uses auto-incrementing primary keys when assigning + | IDs to clients. However, if Passport is installed using the provided + | --uuids switch, this will be set to "true" and UUIDs will be used. + | + */ + + 'client_uuids' => true, + + /* + |-------------------------------------------------------------------------- + | Personal Access Client + |-------------------------------------------------------------------------- + | + | If you enable client hashing, you should set the personal access client + | ID and unhashed secret within your environment file. The values will + | get used while issuing fresh personal access tokens to your users. + | + */ + + 'personal_access_client' => [ + 'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'), + 'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'), + ], + +]; diff --git a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php new file mode 100644 index 0000000..247a167 --- /dev/null +++ b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php @@ -0,0 +1,31 @@ +string('id', 100)->primary(); + $table->unsignedBigInteger('user_id')->index(); + $table->uuid('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'); + } +}; diff --git a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php new file mode 100644 index 0000000..eef9c33 --- /dev/null +++ b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php @@ -0,0 +1,33 @@ +string('id', 100)->primary(); + $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->uuid('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'); + } +}; diff --git a/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php new file mode 100644 index 0000000..b007904 --- /dev/null +++ b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php @@ -0,0 +1,29 @@ +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'); + } +}; diff --git a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php new file mode 100644 index 0000000..8e437ea --- /dev/null +++ b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php @@ -0,0 +1,35 @@ +uuid('id')->primary(); + $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'); + } +}; diff --git a/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php new file mode 100644 index 0000000..15398c9 --- /dev/null +++ b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php @@ -0,0 +1,28 @@ +bigIncrements('id'); + $table->uuid('client_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_personal_access_clients'); + } +}; diff --git a/routes/api/v1/api.php b/routes/api/v1/api.php index f85e293..1f75583 100644 --- a/routes/api/v1/api.php +++ b/routes/api/v1/api.php @@ -3,5 +3,11 @@ declare(strict_types=1); use Illuminate\Support\Facades\Route; +use App\Http\Controllers\V1\AuthController; Route::get('/', static fn () => ['message' => 'Welcome to the API version 1.0 !'])->name('home'); + +Route::controller(AuthController::class)->group(function() { + Route::post('/register', 'register'); + Route::post('/login', 'login'); +}); From 6bf2d838736485a71d8fcc985b5546ff06198797 Mon Sep 17 00:00:00 2001 From: karimalik Date: Sun, 31 Dec 2023 06:58:14 +0100 Subject: [PATCH 3/8] change ulid to uuid --- app/Models/User.php | 4 +++- database/migrations/2014_10_12_000000_create_users_table.php | 2 +- .../2019_12_14_000001_create_personal_access_tokens_table.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 948c2cd..7bd806d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Concerns\HasUlids; +use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -15,7 +16,8 @@ final class User extends Authenticatable { use HasApiTokens; use HasFactory; - use HasUlids; + // use HasUlids; + use HasUuids; use Notifiable; protected $fillable = [ diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index dd9c0a1..6a9f82d 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -10,7 +10,7 @@ public function up(): void { Schema::create('users', static function (Blueprint $table): void { - $table->ulid('id')->primary(); + $table->uuid('id')->primary(); $table->string('name'); $table->string('email')->unique(); diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php index 6795f42..81df00e 100644 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -12,7 +12,7 @@ public function up(): void Schema::create('personal_access_tokens', static function (Blueprint $table): void { $table->id(); - $table->ulidMorphs('tokenable'); + $table->uuidMorphs('tokenable'); $table->string('name'); $table->string('token', 64)->unique(); $table->text('abilities')->nullable(); From ff27031ea22eb65f7e8430e587de38b60117da43 Mon Sep 17 00:00:00 2001 From: karimalik Date: Sun, 31 Dec 2023 07:42:29 +0100 Subject: [PATCH 4/8] login, logout and getuser method --- app/Http/Controllers/V1/AuthController.php | 36 +++++++++++++++++-- app/Http/Requests/Auth/LoginRequest.php | 23 ++++++++++++ ...00002_create_oauth_access_tokens_table.php | 3 +- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 app/Http/Requests/Auth/LoginRequest.php diff --git a/app/Http/Controllers/V1/AuthController.php b/app/Http/Controllers/V1/AuthController.php index ec920ec..ba8a90c 100644 --- a/app/Http/Controllers/V1/AuthController.php +++ b/app/Http/Controllers/V1/AuthController.php @@ -7,8 +7,9 @@ use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; +use App\Http\Requests\Auth\LoginRequest; use App\Http\Requests\Auth\RegisterRequest; - +use Illuminate\Support\Facades\Auth; class AuthController extends Controller { @@ -29,8 +30,39 @@ public function register(RegisterRequest $request): JsonResponse ], Response::HTTP_CREATED); } - public function login() + public function login(LoginRequest $request): JsonResponse + { + $data = $request->validated(); + + if (!Auth::attempt($data)) { + return response()->json([ + 'error' => 'Invalid credentials', + ], Response::HTTP_UNAUTHORIZED); + } + + $user = Auth::user(); + + $token = $user->createToken('AUTHTOKEN')->accessToken; + + return response()->json([ + 'user' => $user, + 'token' => $token + ], Response::HTTP_ACCEPTED); + } + + public function logoutt(): JsonResponse + { + Auth::user()->tokens->each(function ($token, $key) { + $token->delete(); + }); + + return response()->json(['message' => 'logged out successfully'], Response::HTTP_NO_CONTENT); + } + + public function getUser(): JsonResponse { + $user = Auth::user(); + return response()->json(['user' => $user], Response::HTTP_ACCEPTED); } } diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php new file mode 100644 index 0000000..c00f865 --- /dev/null +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -0,0 +1,23 @@ + 'required|string|email|unique:users,email', + "password" => 'required|string|min:8', + ]; + } +} diff --git a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php index eef9c33..c6347d1 100644 --- a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php +++ b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php @@ -13,7 +13,8 @@ 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('user_id')->nullable()->index(); + $table->uuid('user_id')->nullable()->index(); $table->uuid('client_id'); $table->string('name')->nullable(); $table->text('scopes')->nullable(); From 03a4dbe4622f55a8546fd2d363e0319c0b66b2f8 Mon Sep 17 00:00:00 2001 From: karimalik Date: Sun, 31 Dec 2023 10:23:01 +0100 Subject: [PATCH 5/8] fix loginRequest --- app/Http/Controllers/V1/AuthController.php | 2 +- app/Http/Requests/Auth/LoginRequest.php | 2 +- routes/api/v1/api.php | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/V1/AuthController.php b/app/Http/Controllers/V1/AuthController.php index ba8a90c..463b967 100644 --- a/app/Http/Controllers/V1/AuthController.php +++ b/app/Http/Controllers/V1/AuthController.php @@ -50,7 +50,7 @@ public function login(LoginRequest $request): JsonResponse ], Response::HTTP_ACCEPTED); } - public function logoutt(): JsonResponse + public function logout(): JsonResponse { Auth::user()->tokens->each(function ($token, $key) { $token->delete(); diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index c00f865..8f2b024 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -16,7 +16,7 @@ public function authorize(): bool public function rules(): array { return [ - "email" => 'required|string|email|unique:users,email', + "email" => 'required|string|email', "password" => 'required|string|min:8', ]; } diff --git a/routes/api/v1/api.php b/routes/api/v1/api.php index 1f75583..c5946a8 100644 --- a/routes/api/v1/api.php +++ b/routes/api/v1/api.php @@ -10,4 +10,9 @@ Route::controller(AuthController::class)->group(function() { Route::post('/register', 'register'); Route::post('/login', 'login'); + + Route::middleware('auth:api')->group(function (){ + Route::get('/user', 'getUser'); + Route::post('/logout', 'logout'); + }); }); From 0c6178ffd1d7d51bb25605bbda9cd69ffffacce1 Mon Sep 17 00:00:00 2001 From: karimalik Date: Sun, 31 Dec 2023 12:07:15 +0100 Subject: [PATCH 6/8] edit login function --- app/Http/Controllers/V1/AuthController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/V1/AuthController.php b/app/Http/Controllers/V1/AuthController.php index 463b967..de2128d 100644 --- a/app/Http/Controllers/V1/AuthController.php +++ b/app/Http/Controllers/V1/AuthController.php @@ -46,7 +46,7 @@ public function login(LoginRequest $request): JsonResponse return response()->json([ 'user' => $user, - 'token' => $token + 'token' => $token, ], Response::HTTP_ACCEPTED); } From b1e9f65436156a872fc8ed0118e28917c2509f41 Mon Sep 17 00:00:00 2001 From: karimalik Date: Sun, 31 Dec 2023 12:12:03 +0100 Subject: [PATCH 7/8] fix default composer.json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 3fdf50a..57ebaf1 100644 --- a/composer.json +++ b/composer.json @@ -45,6 +45,7 @@ "psr-4": { "App\\": "app/", "Core\\": "core/", + "Skeleton\\": "skeleton/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" } From 0ed4c45a50aa7dbd16747f6d79d6c6231903e2df Mon Sep 17 00:00:00 2001 From: karimalik Date: Sun, 31 Dec 2023 12:49:05 +0100 Subject: [PATCH 8/8] generate skeleton api passport auth --- projects/auth-with-passport/.editorconfig | 18 ++ projects/auth-with-passport/.env.example | 58 +++++ projects/auth-with-passport/.gitignore | 17 ++ projects/auth-with-passport/README.md | 8 + .../app/Console/Commands/.gitkeep | 0 .../auth-with-passport/app/Enum/Error.php | 13 ++ .../app/Exceptions/.gitkeep | 0 .../app/Http/Controllers/Controller.php | 15 ++ .../app/Http/Controllers/HomeController.php | 20 ++ .../app/Http/Controllers/V1/.gitkeep | 0 .../Http/Controllers/V1/AuthController.php | 68 ++++++ .../app/Http/Middleware/CacheHeaders.php | 48 ++++ .../Http/Middleware/ContentTypeMiddleware.php | 27 +++ .../app/Http/Middleware/EncryptCookies.php | 12 + .../Http/Middleware/EnsureEmailIsVerified.php | 24 ++ .../PreventRequestsDuringMaintenance.php | 12 + .../Security/XFrameOptionMiddleware.php | 26 +++ .../app/Http/Middleware/TrimStrings.php | 21 ++ .../app/Http/Middleware/TrustProxies.php | 25 ++ .../app/Http/Middleware/ValidateSignature.php | 12 + .../app/Http/Requests/Auth/LoginRequest.php | 23 ++ .../Http/Requests/Auth/RegisterRequest.php | 24 ++ .../app/Http/Resources/ApiErrorResponse.php | 35 +++ .../app/Http/Resources/DateResource.php | 23 ++ .../app/Http/Resources/V1/.gitkeep | 0 .../auth-with-passport/app/Models/User.php | 36 +++ projects/auth-with-passport/artisan | 53 +++++ projects/auth-with-passport/bootstrap/app.php | 57 +++++ .../bootstrap/cache/.gitignore | 2 + projects/auth-with-passport/composer.json | 98 ++++++++ projects/auth-with-passport/config/app.php | 219 ++++++++++++++++++ projects/auth-with-passport/config/auth.php | 122 ++++++++++ .../config/broadcasting.php | 72 ++++++ projects/auth-with-passport/config/cache.php | 112 +++++++++ projects/auth-with-passport/config/cors.php | 36 +++ .../auth-with-passport/config/database.php | 153 ++++++++++++ .../auth-with-passport/config/filesystems.php | 78 +++++++ .../auth-with-passport/config/hashing.php | 54 +++++ .../auth-with-passport/config/headers.php | 22 ++ .../auth-with-passport/config/logging.php | 125 ++++++++++ projects/auth-with-passport/config/mail.php | 126 ++++++++++ .../auth-with-passport/config/passport.php | 62 +++++ projects/auth-with-passport/config/queue.php | 95 ++++++++ .../auth-with-passport/config/sanctum.php | 54 +++++ .../auth-with-passport/config/services.php | 36 +++ .../auth-with-passport/config/session.php | 203 ++++++++++++++++ .../auth-with-passport/config/treblle.php | 36 +++ projects/auth-with-passport/config/view.php | 38 +++ .../core/Console/Kernel.php | 25 ++ .../core/Exceptions/Handler.php | 28 +++ .../core/Http/Controllers/Controller.php | 15 ++ .../auth-with-passport/core/Http/Kernel.php | 68 ++++++ .../core/Providers/AppServiceProvider.php | 15 ++ .../core/Providers/AuthServiceProvider.php | 18 ++ .../Providers/BroadcastServiceProvider.php | 17 ++ .../core/Providers/EventServiceProvider.php | 18 ++ .../core/Providers/RouteServiceProvider.php | 39 ++++ .../auth-with-passport/database/.gitignore | 1 + .../database/factories/UserFactory.php | 35 +++ .../2014_10_12_000000_create_users_table.php | 28 +++ ...000_create_password_reset_tokens_table.php | 23 ++ ...1_000001_create_oauth_auth_codes_table.php | 31 +++ ...00002_create_oauth_access_tokens_table.php | 34 +++ ...0003_create_oauth_refresh_tokens_table.php | 29 +++ ...6_01_000004_create_oauth_clients_table.php | 35 +++ ...te_oauth_personal_access_clients_table.php | 28 +++ ..._08_19_000000_create_failed_jobs_table.php | 27 +++ ...01_create_personal_access_tokens_table.php | 30 +++ .../database/seeders/DatabaseSeeder.php | 19 ++ projects/auth-with-passport/lang/en/auth.php | 22 ++ .../auth-with-passport/lang/en/messages.php | 9 + .../auth-with-passport/lang/en/pagination.php | 21 ++ .../auth-with-passport/lang/en/passwords.php | 24 ++ .../auth-with-passport/lang/en/validation.php | 186 +++++++++++++++ .../auth-with-passport/lang/fr/messages.php | 9 + projects/auth-with-passport/phpstan.neon | 21 ++ projects/auth-with-passport/phpunit.xml | 31 +++ projects/auth-with-passport/pint.json | 42 ++++ projects/auth-with-passport/public/.htaccess | 21 ++ .../auth-with-passport/public/favicon.ico | 0 projects/auth-with-passport/public/index.php | 57 +++++ projects/auth-with-passport/public/robots.txt | 2 + .../resources/views/.gitkeep | 1 + .../auth-with-passport/routes/api/routes.php | 12 + .../auth-with-passport/routes/api/v1/api.php | 18 ++ .../routes/sockets/routes.php | 11 + .../auth-with-passport/storage/app/.gitignore | 3 + .../storage/app/public/.gitignore | 2 + .../storage/framework/.gitignore | 9 + .../storage/framework/cache/.gitignore | 3 + .../storage/framework/cache/data/.gitignore | 2 + .../storage/framework/sessions/.gitignore | 2 + .../storage/framework/testing/.gitignore | 2 + .../storage/framework/views/.gitignore | 2 + .../storage/logs/.gitignore | 2 + projects/auth-with-passport/stubs/cast.stub | 31 +++ .../auth-with-passport/stubs/console.stub | 19 ++ .../stubs/controller.invokable.stub | 15 ++ projects/auth-with-passport/stubs/event.stub | 35 +++ .../auth-with-passport/stubs/factory.stub | 19 ++ .../auth-with-passport/stubs/job.queued.stub | 27 +++ projects/auth-with-passport/stubs/mail.stub | 41 ++++ .../stubs/markdown-mail.stub | 41 ++++ .../stubs/markdown-notification.stub | 50 ++++ .../auth-with-passport/stubs/middleware.stub | 17 ++ .../stubs/migration.create.stub | 26 +++ .../auth-with-passport/stubs/migration.stub | 20 ++ .../stubs/migration.update.stub | 24 ++ .../auth-with-passport/stubs/model.pivot.stub | 12 + projects/auth-with-passport/stubs/model.stub | 19 ++ .../stubs/notification.stub | 41 ++++ projects/auth-with-passport/stubs/policy.stub | 47 ++++ .../auth-with-passport/stubs/provider.stub | 20 ++ .../auth-with-passport/stubs/request.stub | 22 ++ .../auth-with-passport/stubs/resource.stub | 21 ++ projects/auth-with-passport/stubs/rule.stub | 19 ++ projects/auth-with-passport/stubs/scope.stub | 17 ++ projects/auth-with-passport/stubs/seeder.stub | 16 ++ .../tests/CreatesApplication.php | 20 ++ .../Feature/Http/Controllers/V1/.gitkeep | 0 projects/auth-with-passport/tests/Pest.php | 11 + .../auth-with-passport/tests/TestCase.php | 12 + .../auth-with-passport/tests/Unit/.gitkeep | 0 123 files changed, 4137 insertions(+) create mode 100644 projects/auth-with-passport/.editorconfig create mode 100644 projects/auth-with-passport/.env.example create mode 100644 projects/auth-with-passport/.gitignore create mode 100644 projects/auth-with-passport/README.md create mode 100644 projects/auth-with-passport/app/Console/Commands/.gitkeep create mode 100644 projects/auth-with-passport/app/Enum/Error.php create mode 100644 projects/auth-with-passport/app/Exceptions/.gitkeep create mode 100644 projects/auth-with-passport/app/Http/Controllers/Controller.php create mode 100644 projects/auth-with-passport/app/Http/Controllers/HomeController.php create mode 100644 projects/auth-with-passport/app/Http/Controllers/V1/.gitkeep create mode 100644 projects/auth-with-passport/app/Http/Controllers/V1/AuthController.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/CacheHeaders.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/ContentTypeMiddleware.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/EncryptCookies.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/EnsureEmailIsVerified.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/PreventRequestsDuringMaintenance.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/Security/XFrameOptionMiddleware.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/TrimStrings.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/TrustProxies.php create mode 100644 projects/auth-with-passport/app/Http/Middleware/ValidateSignature.php create mode 100644 projects/auth-with-passport/app/Http/Requests/Auth/LoginRequest.php create mode 100644 projects/auth-with-passport/app/Http/Requests/Auth/RegisterRequest.php create mode 100644 projects/auth-with-passport/app/Http/Resources/ApiErrorResponse.php create mode 100644 projects/auth-with-passport/app/Http/Resources/DateResource.php create mode 100644 projects/auth-with-passport/app/Http/Resources/V1/.gitkeep create mode 100644 projects/auth-with-passport/app/Models/User.php create mode 100755 projects/auth-with-passport/artisan create mode 100644 projects/auth-with-passport/bootstrap/app.php create mode 100644 projects/auth-with-passport/bootstrap/cache/.gitignore create mode 100644 projects/auth-with-passport/composer.json create mode 100644 projects/auth-with-passport/config/app.php create mode 100644 projects/auth-with-passport/config/auth.php create mode 100644 projects/auth-with-passport/config/broadcasting.php create mode 100644 projects/auth-with-passport/config/cache.php create mode 100644 projects/auth-with-passport/config/cors.php create mode 100644 projects/auth-with-passport/config/database.php create mode 100644 projects/auth-with-passport/config/filesystems.php create mode 100644 projects/auth-with-passport/config/hashing.php create mode 100644 projects/auth-with-passport/config/headers.php create mode 100644 projects/auth-with-passport/config/logging.php create mode 100644 projects/auth-with-passport/config/mail.php create mode 100644 projects/auth-with-passport/config/passport.php create mode 100644 projects/auth-with-passport/config/queue.php create mode 100644 projects/auth-with-passport/config/sanctum.php create mode 100644 projects/auth-with-passport/config/services.php create mode 100644 projects/auth-with-passport/config/session.php create mode 100644 projects/auth-with-passport/config/treblle.php create mode 100644 projects/auth-with-passport/config/view.php create mode 100644 projects/auth-with-passport/core/Console/Kernel.php create mode 100644 projects/auth-with-passport/core/Exceptions/Handler.php create mode 100644 projects/auth-with-passport/core/Http/Controllers/Controller.php create mode 100644 projects/auth-with-passport/core/Http/Kernel.php create mode 100644 projects/auth-with-passport/core/Providers/AppServiceProvider.php create mode 100644 projects/auth-with-passport/core/Providers/AuthServiceProvider.php create mode 100644 projects/auth-with-passport/core/Providers/BroadcastServiceProvider.php create mode 100644 projects/auth-with-passport/core/Providers/EventServiceProvider.php create mode 100644 projects/auth-with-passport/core/Providers/RouteServiceProvider.php create mode 100644 projects/auth-with-passport/database/.gitignore create mode 100644 projects/auth-with-passport/database/factories/UserFactory.php create mode 100644 projects/auth-with-passport/database/migrations/2014_10_12_000000_create_users_table.php create mode 100644 projects/auth-with-passport/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php create mode 100644 projects/auth-with-passport/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php create mode 100644 projects/auth-with-passport/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php create mode 100644 projects/auth-with-passport/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php create mode 100644 projects/auth-with-passport/database/migrations/2016_06_01_000004_create_oauth_clients_table.php create mode 100644 projects/auth-with-passport/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php create mode 100644 projects/auth-with-passport/database/migrations/2019_08_19_000000_create_failed_jobs_table.php create mode 100644 projects/auth-with-passport/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php create mode 100644 projects/auth-with-passport/database/seeders/DatabaseSeeder.php create mode 100644 projects/auth-with-passport/lang/en/auth.php create mode 100644 projects/auth-with-passport/lang/en/messages.php create mode 100644 projects/auth-with-passport/lang/en/pagination.php create mode 100644 projects/auth-with-passport/lang/en/passwords.php create mode 100644 projects/auth-with-passport/lang/en/validation.php create mode 100644 projects/auth-with-passport/lang/fr/messages.php create mode 100644 projects/auth-with-passport/phpstan.neon create mode 100644 projects/auth-with-passport/phpunit.xml create mode 100644 projects/auth-with-passport/pint.json create mode 100644 projects/auth-with-passport/public/.htaccess create mode 100644 projects/auth-with-passport/public/favicon.ico create mode 100644 projects/auth-with-passport/public/index.php create mode 100644 projects/auth-with-passport/public/robots.txt create mode 100644 projects/auth-with-passport/resources/views/.gitkeep create mode 100644 projects/auth-with-passport/routes/api/routes.php create mode 100644 projects/auth-with-passport/routes/api/v1/api.php create mode 100644 projects/auth-with-passport/routes/sockets/routes.php create mode 100644 projects/auth-with-passport/storage/app/.gitignore create mode 100644 projects/auth-with-passport/storage/app/public/.gitignore create mode 100644 projects/auth-with-passport/storage/framework/.gitignore create mode 100644 projects/auth-with-passport/storage/framework/cache/.gitignore create mode 100644 projects/auth-with-passport/storage/framework/cache/data/.gitignore create mode 100644 projects/auth-with-passport/storage/framework/sessions/.gitignore create mode 100644 projects/auth-with-passport/storage/framework/testing/.gitignore create mode 100644 projects/auth-with-passport/storage/framework/views/.gitignore create mode 100644 projects/auth-with-passport/storage/logs/.gitignore create mode 100644 projects/auth-with-passport/stubs/cast.stub create mode 100644 projects/auth-with-passport/stubs/console.stub create mode 100644 projects/auth-with-passport/stubs/controller.invokable.stub create mode 100644 projects/auth-with-passport/stubs/event.stub create mode 100644 projects/auth-with-passport/stubs/factory.stub create mode 100644 projects/auth-with-passport/stubs/job.queued.stub create mode 100644 projects/auth-with-passport/stubs/mail.stub create mode 100644 projects/auth-with-passport/stubs/markdown-mail.stub create mode 100644 projects/auth-with-passport/stubs/markdown-notification.stub create mode 100644 projects/auth-with-passport/stubs/middleware.stub create mode 100644 projects/auth-with-passport/stubs/migration.create.stub create mode 100644 projects/auth-with-passport/stubs/migration.stub create mode 100644 projects/auth-with-passport/stubs/migration.update.stub create mode 100644 projects/auth-with-passport/stubs/model.pivot.stub create mode 100644 projects/auth-with-passport/stubs/model.stub create mode 100644 projects/auth-with-passport/stubs/notification.stub create mode 100644 projects/auth-with-passport/stubs/policy.stub create mode 100644 projects/auth-with-passport/stubs/provider.stub create mode 100644 projects/auth-with-passport/stubs/request.stub create mode 100644 projects/auth-with-passport/stubs/resource.stub create mode 100644 projects/auth-with-passport/stubs/rule.stub create mode 100644 projects/auth-with-passport/stubs/scope.stub create mode 100644 projects/auth-with-passport/stubs/seeder.stub create mode 100644 projects/auth-with-passport/tests/CreatesApplication.php create mode 100644 projects/auth-with-passport/tests/Feature/Http/Controllers/V1/.gitkeep create mode 100644 projects/auth-with-passport/tests/Pest.php create mode 100644 projects/auth-with-passport/tests/TestCase.php create mode 100644 projects/auth-with-passport/tests/Unit/.gitkeep diff --git a/projects/auth-with-passport/.editorconfig b/projects/auth-with-passport/.editorconfig new file mode 100644 index 0000000..be9f8c9 --- /dev/null +++ b/projects/auth-with-passport/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml,json}] +indent_size = 2 + +[docker-compose.yml] +indent_size = 4 diff --git a/projects/auth-with-passport/.env.example b/projects/auth-with-passport/.env.example new file mode 100644 index 0000000..a263ec7 --- /dev/null +++ b/projects/auth-with-passport/.env.example @@ -0,0 +1,58 @@ +APP_NAME="Laravel API Skeleton" +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=api +DB_USERNAME=root +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DISK=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=mailpit +MAIL_PORT=1025 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS="hello@example.com" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_HOST= +PUSHER_PORT=443 +PUSHER_SCHEME=https +PUSHER_APP_CLUSTER=mt1 + +VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +VITE_PUSHER_HOST="${PUSHER_HOST}" +VITE_PUSHER_PORT="${PUSHER_PORT}" +VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" +VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/projects/auth-with-passport/.gitignore b/projects/auth-with-passport/.gitignore new file mode 100644 index 0000000..2b86e03 --- /dev/null +++ b/projects/auth-with-passport/.gitignore @@ -0,0 +1,17 @@ +/.phpunit.cache +/public/storage +/storage/*.key +/vendor +/node_modules +.env +.env.backup +.env.production +.phpunit.result.cache +Homestead.json +Homestead.yaml +npm-debug.log +yarn-error.log +composer.lock +/.fleet +/.idea +/.vscode diff --git a/projects/auth-with-passport/README.md b/projects/auth-with-passport/README.md new file mode 100644 index 0000000..76cfff2 --- /dev/null +++ b/projects/auth-with-passport/README.md @@ -0,0 +1,8 @@ +# Laravel API Skeleton - Example +This project is a skeleton for building an API with Laravel. It is the simplest skeleton and contains only the basic packages to build an API. + +## Installation + +```bash +composer require laravelcm/api-skeleton +``` diff --git a/projects/auth-with-passport/app/Console/Commands/.gitkeep b/projects/auth-with-passport/app/Console/Commands/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/projects/auth-with-passport/app/Enum/Error.php b/projects/auth-with-passport/app/Enum/Error.php new file mode 100644 index 0000000..1dd303e --- /dev/null +++ b/projects/auth-with-passport/app/Enum/Error.php @@ -0,0 +1,13 @@ + __('messages.welcome'), + ], + ); + } +} diff --git a/projects/auth-with-passport/app/Http/Controllers/V1/.gitkeep b/projects/auth-with-passport/app/Http/Controllers/V1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/projects/auth-with-passport/app/Http/Controllers/V1/AuthController.php b/projects/auth-with-passport/app/Http/Controllers/V1/AuthController.php new file mode 100644 index 0000000..de2128d --- /dev/null +++ b/projects/auth-with-passport/app/Http/Controllers/V1/AuthController.php @@ -0,0 +1,68 @@ +validated(); + + $data['password'] = bcrypt($request->password); + + $user = User::create($data); + + $token = $user->createToken('AUTHTOKEN')->accessToken; + + return response()->json([ + 'message' => 'Success', + 'user' => $user, + 'token' => $token, + ], Response::HTTP_CREATED); + } + + public function login(LoginRequest $request): JsonResponse + { + $data = $request->validated(); + + if (!Auth::attempt($data)) { + return response()->json([ + 'error' => 'Invalid credentials', + ], Response::HTTP_UNAUTHORIZED); + } + + $user = Auth::user(); + + $token = $user->createToken('AUTHTOKEN')->accessToken; + + return response()->json([ + 'user' => $user, + 'token' => $token, + ], Response::HTTP_ACCEPTED); + } + + public function logout(): JsonResponse + { + Auth::user()->tokens->each(function ($token, $key) { + $token->delete(); + }); + + return response()->json(['message' => 'logged out successfully'], Response::HTTP_NO_CONTENT); + } + + public function getUser(): JsonResponse + { + $user = Auth::user(); + + return response()->json(['user' => $user], Response::HTTP_ACCEPTED); + } +} diff --git a/projects/auth-with-passport/app/Http/Middleware/CacheHeaders.php b/projects/auth-with-passport/app/Http/Middleware/CacheHeaders.php new file mode 100644 index 0000000..a363563 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Middleware/CacheHeaders.php @@ -0,0 +1,48 @@ +setCache( + options: [ + 'private' => true, + 'max_age' => 0, + 's_maxage' => 0, + 'no_store' => true + ], + ); + } else { + $response->setCache( + options: [ + 'public' => true, + 'max_age' => 60, + 's_maxage' => 60, + ], + ); + + foreach ($response->headers->getCookies() as $cookie) { + $response->headers->removeCookie( + name: $cookie->getName(), + ); + } + } + + return $response; + } +} diff --git a/projects/auth-with-passport/app/Http/Middleware/ContentTypeMiddleware.php b/projects/auth-with-passport/app/Http/Middleware/ContentTypeMiddleware.php new file mode 100644 index 0000000..49da605 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Middleware/ContentTypeMiddleware.php @@ -0,0 +1,27 @@ +headers->add([ + 'Accept' => 'application/json', + 'Content-Type' => 'application/vnd.api+json', + ]); + + return $response; + } +} diff --git a/projects/auth-with-passport/app/Http/Middleware/EncryptCookies.php b/projects/auth-with-passport/app/Http/Middleware/EncryptCookies.php new file mode 100644 index 0000000..dddc45b --- /dev/null +++ b/projects/auth-with-passport/app/Http/Middleware/EncryptCookies.php @@ -0,0 +1,12 @@ +user() || + ($request->user() instanceof MustVerifyEmail && + ! $request->user()->hasVerifiedEmail())) { + return response()->json(['message' => __('Your email address is not verified.')], 409); + } + + return $next($request); + } +} diff --git a/projects/auth-with-passport/app/Http/Middleware/PreventRequestsDuringMaintenance.php b/projects/auth-with-passport/app/Http/Middleware/PreventRequestsDuringMaintenance.php new file mode 100644 index 0000000..3422e26 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Middleware/PreventRequestsDuringMaintenance.php @@ -0,0 +1,12 @@ +headers->add([ + 'X-Frame-Options' => 'deny', + ]); + + return $response; + } +} diff --git a/projects/auth-with-passport/app/Http/Middleware/TrimStrings.php b/projects/auth-with-passport/app/Http/Middleware/TrimStrings.php new file mode 100644 index 0000000..b7b3a49 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Middleware/TrimStrings.php @@ -0,0 +1,21 @@ + + */ + protected $except = [ + 'current_password', + 'password', + 'password_confirmation', + ]; +} diff --git a/projects/auth-with-passport/app/Http/Middleware/TrustProxies.php b/projects/auth-with-passport/app/Http/Middleware/TrustProxies.php new file mode 100644 index 0000000..5924ec6 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Middleware/TrustProxies.php @@ -0,0 +1,25 @@ +|string|null + */ + protected $proxies; + + protected $headers = + Request::HEADER_X_FORWARDED_FOR | + Request::HEADER_X_FORWARDED_HOST | + Request::HEADER_X_FORWARDED_PORT | + Request::HEADER_X_FORWARDED_PROTO | + Request::HEADER_X_FORWARDED_AWS_ELB; +} diff --git a/projects/auth-with-passport/app/Http/Middleware/ValidateSignature.php b/projects/auth-with-passport/app/Http/Middleware/ValidateSignature.php new file mode 100644 index 0000000..280eac0 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Middleware/ValidateSignature.php @@ -0,0 +1,12 @@ + 'required|string|email', + "password" => 'required|string|min:8', + ]; + } +} diff --git a/projects/auth-with-passport/app/Http/Requests/Auth/RegisterRequest.php b/projects/auth-with-passport/app/Http/Requests/Auth/RegisterRequest.php new file mode 100644 index 0000000..9be9461 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Requests/Auth/RegisterRequest.php @@ -0,0 +1,24 @@ + 'required|string', + "email" => 'required|email|unique:users,email', + "password" => 'required|string|min:8' + ]; + } +} diff --git a/projects/auth-with-passport/app/Http/Resources/ApiErrorResponse.php b/projects/auth-with-passport/app/Http/Resources/ApiErrorResponse.php new file mode 100644 index 0000000..fd24fd1 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Resources/ApiErrorResponse.php @@ -0,0 +1,35 @@ + $this->title, + 'description' => $this->description, + 'code' => $this->code->value, + 'status' => $this->status->value, + ], + status: $this->status->value, + ); + } +} diff --git a/projects/auth-with-passport/app/Http/Resources/DateResource.php b/projects/auth-with-passport/app/Http/Resources/DateResource.php new file mode 100644 index 0000000..4703fd4 --- /dev/null +++ b/projects/auth-with-passport/app/Http/Resources/DateResource.php @@ -0,0 +1,23 @@ + $this->resource->diffForHumans(), + 'string' => $this->resource->toDateTimeString(), + ]; + } +} diff --git a/projects/auth-with-passport/app/Http/Resources/V1/.gitkeep b/projects/auth-with-passport/app/Http/Resources/V1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/projects/auth-with-passport/app/Models/User.php b/projects/auth-with-passport/app/Models/User.php new file mode 100644 index 0000000..7bd806d --- /dev/null +++ b/projects/auth-with-passport/app/Models/User.php @@ -0,0 +1,36 @@ + 'datetime', + ]; +} diff --git a/projects/auth-with-passport/artisan b/projects/auth-with-passport/artisan new file mode 100755 index 0000000..67a3329 --- /dev/null +++ b/projects/auth-with-passport/artisan @@ -0,0 +1,53 @@ +#!/usr/bin/env php +make(Illuminate\Contracts\Console\Kernel::class); + +$status = $kernel->handle( + $input = new Symfony\Component\Console\Input\ArgvInput, + new Symfony\Component\Console\Output\ConsoleOutput +); + +/* +|-------------------------------------------------------------------------- +| Shutdown The Application +|-------------------------------------------------------------------------- +| +| Once Artisan has finished running, we will fire off the shutdown events +| so that any final work may be done by the application before we shut +| down the process. This is the last thing to happen to the request. +| +*/ + +$kernel->terminate($input, $status); + +exit($status); diff --git a/projects/auth-with-passport/bootstrap/app.php b/projects/auth-with-passport/bootstrap/app.php new file mode 100644 index 0000000..b16512a --- /dev/null +++ b/projects/auth-with-passport/bootstrap/app.php @@ -0,0 +1,57 @@ +singleton( + Illuminate\Contracts\Http\Kernel::class, + Core\Http\Kernel::class +); + +$app->singleton( + Illuminate\Contracts\Console\Kernel::class, + Core\Console\Kernel::class +); + +$app->singleton( + Illuminate\Contracts\Debug\ExceptionHandler::class, + Core\Exceptions\Handler::class +); + +/* +|-------------------------------------------------------------------------- +| Return The Application +|-------------------------------------------------------------------------- +| +| This script returns the application instance. The instance is given to +| the calling script so we can separate the building of the instances +| from the actual running of the application and sending responses. +| +*/ + +return $app; diff --git a/projects/auth-with-passport/bootstrap/cache/.gitignore b/projects/auth-with-passport/bootstrap/cache/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/projects/auth-with-passport/bootstrap/cache/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/projects/auth-with-passport/composer.json b/projects/auth-with-passport/composer.json new file mode 100644 index 0000000..57ebaf1 --- /dev/null +++ b/projects/auth-with-passport/composer.json @@ -0,0 +1,98 @@ +{ + "name": "laravelcm/api-skeleton-default", + "type": "project", + "description": "Skeleton for building APIs with Laravel", + "keywords": [ + "framework", + "laravel", + "api" + ], + "license": "MIT", + "authors": [ + { + "name": "Arthur Monney", + "email": "monneylobe@gmail.com", + "homepage": "https://arthurmonney.me", + "role": "Developer" + } + ], + "require": { + "php": "^8.2", + "guzzlehttp/guzzle": "^7.5", + "juststeveking/http-status-code": "^3.0.2", + "juststeveking/launchpad": "dev-main", + "laravel/framework": "^10.2", + "laravel/passport": "^11.10", + "laravel/sanctum": "^3.2.1", + "laravel/tinker": "^2.8.1", + "timacdonald/json-api": "v1.0.0-beta.4", + "treblle/security-headers": "^0.0.3" + }, + "require-dev": { + "fakerphp/faker": "^1.21.0", + "laravel/pint": "^1.6", + "laravel/sail": "^1.21.1", + "mockery/mockery": "^1.5.1", + "nunomaduro/collision": "^6.4", + "nunomaduro/larastan": "^2.5.1", + "pestphp/pest": "^1.22.5", + "pestphp/pest-plugin-laravel": "^1.4", + "spatie/laravel-ignition": "^2.0", + "symfony/console": "^6.3", + "symfony/filesystem": "^6.3" + }, + "autoload": { + "psr-4": { + "App\\": "app/", + "Core\\": "core/", + "Skeleton\\": "skeleton/", + "Database\\Factories\\": "database/factories/", + "Database\\Seeders\\": "database/seeders/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "scripts": { + "post-autoload-dump": [ + "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", + "@php artisan package:discover --ansi" + ], + "post-update-cmd": [ + "@php artisan vendor:publish --tag=laravel-assets --ansi --force" + ], + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ], + "pint": [ + "./vendor/bin/pint" + ], + "stan": [ + "./vendor/bin/phpstan analyse --memory-limit=3g" + ], + "test": [ + "@php artisan test" + ] + }, + "extra": { + "laravel": { + "dont-discover": [] + } + }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "php-http/discovery": true + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/projects/auth-with-passport/config/app.php b/projects/auth-with-passport/config/app.php new file mode 100644 index 0000000..5addcae --- /dev/null +++ b/projects/auth-with-passport/config/app.php @@ -0,0 +1,219 @@ + env('APP_NAME', 'Laravel'), + + /* + |-------------------------------------------------------------------------- + | Application Environment + |-------------------------------------------------------------------------- + | + | This value determines the "environment" your application is currently + | running in. This may determine how you prefer to configure various + | services the application utilizes. Set this in your ".env" file. + | + */ + + 'env' => env('APP_ENV', 'production'), + + /* + |-------------------------------------------------------------------------- + | Application Debug Mode + |-------------------------------------------------------------------------- + | + | When your application is in debug mode, detailed error messages with + | stack traces will be shown on every error that occurs within your + | application. If disabled, a simple generic error page is shown. + | + */ + + 'debug' => (bool) env('APP_DEBUG', false), + + /* + |-------------------------------------------------------------------------- + | Application URL + |-------------------------------------------------------------------------- + | + | This URL is used by the console to properly generate URLs when using + | the Artisan command line tool. You should set this to the root of + | your application so that it is used when running Artisan tasks. + | + */ + + 'url' => env('APP_URL', 'http://localhost'), + + 'frontend_url' => env('FRONTEND_URL', 'http://localhost:3000'), + + 'asset_url' => env('ASSET_URL'), + + /* + |-------------------------------------------------------------------------- + | Application Timezone + |-------------------------------------------------------------------------- + | + | Here you may specify the default timezone for your application, which + | will be used by the PHP date and date-time functions. We have gone + | ahead and set this to a sensible default for you out of the box. + | + */ + + 'timezone' => 'UTC', + + /* + |-------------------------------------------------------------------------- + | Application Locale Configuration + |-------------------------------------------------------------------------- + | + | The application locale determines the default locale that will be used + | by the translation service provider. You are free to set this value + | to any of the locales which will be supported by the application. + | + */ + + 'locale' => 'en', + + /* + |-------------------------------------------------------------------------- + | Application Fallback Locale + |-------------------------------------------------------------------------- + | + | The fallback locale determines the locale to use when the current one + | is not available. You may change the value to correspond to any of + | the language folders that are provided through your application. + | + */ + + 'fallback_locale' => 'en', + + /* + |-------------------------------------------------------------------------- + | Faker Locale + |-------------------------------------------------------------------------- + | + | This locale will be used by the Faker PHP library when generating fake + | data for your database seeds. For example, this will be used to get + | localized telephone numbers, street address information and more. + | + */ + + 'faker_locale' => 'en_US', + + /* + |-------------------------------------------------------------------------- + | Encryption Key + |-------------------------------------------------------------------------- + | + | This key is used by the Illuminate encrypter service and should be set + | to a random, 32 character string, otherwise these encrypted strings + | will not be safe. Please do this before deploying an application! + | + */ + + 'key' => env('APP_KEY'), + + 'cipher' => 'AES-256-CBC', + + /* + |-------------------------------------------------------------------------- + | Maintenance Mode Driver + |-------------------------------------------------------------------------- + | + | These configuration options determine the driver used to determine and + | manage Laravel's "maintenance mode" status. The "cache" driver will + | allow maintenance mode to be controlled across multiple machines. + | + | Supported drivers: "file", "cache" + | + */ + + 'maintenance' => [ + 'driver' => 'file', + // 'store' => 'redis', + ], + + /* + |-------------------------------------------------------------------------- + | Autoloaded Service Providers + |-------------------------------------------------------------------------- + | + | The service providers listed here will be automatically loaded on the + | request to your application. Feel free to add your own services to + | this array to grant expanded functionality to your applications. + | + */ + + 'providers' => [ + + /* + * Laravel Framework Service Providers... + */ + Illuminate\Auth\AuthServiceProvider::class, + Illuminate\Broadcasting\BroadcastServiceProvider::class, + Illuminate\Bus\BusServiceProvider::class, + Illuminate\Cache\CacheServiceProvider::class, + Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, + Illuminate\Cookie\CookieServiceProvider::class, + Illuminate\Database\DatabaseServiceProvider::class, + Illuminate\Encryption\EncryptionServiceProvider::class, + Illuminate\Filesystem\FilesystemServiceProvider::class, + Illuminate\Foundation\Providers\FoundationServiceProvider::class, + Illuminate\Hashing\HashServiceProvider::class, + Illuminate\Mail\MailServiceProvider::class, + Illuminate\Notifications\NotificationServiceProvider::class, + Illuminate\Pagination\PaginationServiceProvider::class, + Illuminate\Pipeline\PipelineServiceProvider::class, + Illuminate\Queue\QueueServiceProvider::class, + Illuminate\Redis\RedisServiceProvider::class, + Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, + Illuminate\Session\SessionServiceProvider::class, + Illuminate\Translation\TranslationServiceProvider::class, + Illuminate\Validation\ValidationServiceProvider::class, + Illuminate\View\ViewServiceProvider::class, + + /* + * Package Service Providers... + */ + + /* + * Core Service Providers... + */ + Core\Providers\AppServiceProvider::class, + Core\Providers\AuthServiceProvider::class, + // Core\Providers\BroadcastServiceProvider::class, + Core\Providers\EventServiceProvider::class, + Core\Providers\RouteServiceProvider::class, + + ], + + /* + |-------------------------------------------------------------------------- + | Class Aliases + |-------------------------------------------------------------------------- + | + | This array of class aliases will be registered when this application + | is started. However, feel free to register as many as you wish as + | the aliases are "lazy" loaded so they don't hinder performance. + | + */ + + 'aliases' => Facade::defaultAliases()->merge([ + // 'ExampleClass' => App\Example\ExampleClass::class, + ])->toArray(), + +]; diff --git a/projects/auth-with-passport/config/auth.php b/projects/auth-with-passport/config/auth.php new file mode 100644 index 0000000..217449e --- /dev/null +++ b/projects/auth-with-passport/config/auth.php @@ -0,0 +1,122 @@ + [ + 'guard' => 'web', + 'passwords' => 'users', + ], + + /* + |-------------------------------------------------------------------------- + | Authentication Guards + |-------------------------------------------------------------------------- + | + | Next, you may define every authentication guard for your application. + | Of course, a great default configuration has been defined for you + | here which uses session storage and the Eloquent user provider. + | + | All authentication drivers have a user provider. This defines how the + | users are actually retrieved out of your database or other storage + | mechanisms used by this application to persist your user's data. + | + | Supported: "session" + | + */ + + 'guards' => [ + 'web' => [ + 'driver' => 'session', + 'provider' => 'users', + ], + + 'api' => [ + 'driver' => 'passport', + 'provider' => 'users', + ], + ], + + /* + |-------------------------------------------------------------------------- + | User Providers + |-------------------------------------------------------------------------- + | + | All authentication drivers have a user provider. This defines how the + | users are actually retrieved out of your database or other storage + | mechanisms used by this application to persist your user's data. + | + | If you have multiple user tables or models you may configure multiple + | sources which represent each model / table. These sources may then + | be assigned to any extra authentication guards you have defined. + | + | Supported: "database", "eloquent" + | + */ + + 'providers' => [ + 'users' => [ + 'driver' => 'eloquent', + 'model' => App\Models\User::class, + ], + + // 'users' => [ + // 'driver' => 'database', + // 'table' => 'users', + // ], + ], + + /* + |-------------------------------------------------------------------------- + | Resetting Passwords + |-------------------------------------------------------------------------- + | + | You may specify multiple password reset configurations if you have more + | than one user table or model in the application and you want to have + | separate password reset settings based on the specific user types. + | + | 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' => 'password_reset_tokens', + 'expire' => 60, + 'throttle' => 60, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Password Confirmation Timeout + |-------------------------------------------------------------------------- + | + | Here you may define the amount of seconds before a password confirmation + | times out and the user is prompted to re-enter their password via the + | confirmation screen. By default, the timeout lasts for three hours. + | + */ + + 'password_timeout' => 10800, + +]; diff --git a/projects/auth-with-passport/config/broadcasting.php b/projects/auth-with-passport/config/broadcasting.php new file mode 100644 index 0000000..37d4ded --- /dev/null +++ b/projects/auth-with-passport/config/broadcasting.php @@ -0,0 +1,72 @@ + env('BROADCAST_DRIVER', 'null'), + + /* + |-------------------------------------------------------------------------- + | Broadcast Connections + |-------------------------------------------------------------------------- + | + | Here you may define all of the broadcast connections that will be used + | to broadcast events to other systems or over websockets. Samples of + | each available type of connection are provided inside this array. + | + */ + + 'connections' => [ + + 'pusher' => [ + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), + 'options' => [ + 'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com', + 'port' => env('PUSHER_PORT', 443), + 'scheme' => env('PUSHER_SCHEME', 'https'), + 'encrypted' => true, + 'useTLS' => 'https' === env('PUSHER_SCHEME', 'https'), + ], + 'client_options' => [ + // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html + ], + ], + + 'ably' => [ + 'driver' => 'ably', + 'key' => env('ABLY_KEY'), + ], + + 'redis' => [ + 'driver' => 'redis', + 'connection' => 'default', + ], + + 'log' => [ + 'driver' => 'log', + ], + + 'null' => [ + 'driver' => 'null', + ], + + ], + +]; diff --git a/projects/auth-with-passport/config/cache.php b/projects/auth-with-passport/config/cache.php new file mode 100644 index 0000000..c82c508 --- /dev/null +++ b/projects/auth-with-passport/config/cache.php @@ -0,0 +1,112 @@ + env('CACHE_DRIVER', 'file'), + + /* + |-------------------------------------------------------------------------- + | Cache Stores + |-------------------------------------------------------------------------- + | + | Here you may define all of the cache "stores" for your application as + | well as their drivers. You may even define multiple stores for the + | same cache driver to group types of items stored in your caches. + | + | Supported drivers: "apc", "array", "database", "file", + | "memcached", "redis", "dynamodb", "octane", "null" + | + */ + + 'stores' => [ + + 'apc' => [ + 'driver' => 'apc', + ], + + 'array' => [ + 'driver' => 'array', + 'serialize' => false, + ], + + 'database' => [ + 'driver' => 'database', + 'table' => 'cache', + 'connection' => null, + 'lock_connection' => null, + ], + + 'file' => [ + 'driver' => 'file', + 'path' => storage_path('framework/cache/data'), + ], + + 'memcached' => [ + 'driver' => 'memcached', + 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), + 'sasl' => [ + env('MEMCACHED_USERNAME'), + env('MEMCACHED_PASSWORD'), + ], + 'options' => [ + // Memcached::OPT_CONNECT_TIMEOUT => 2000, + ], + 'servers' => [ + [ + 'host' => env('MEMCACHED_HOST', '127.0.0.1'), + 'port' => env('MEMCACHED_PORT', 11211), + 'weight' => 100, + ], + ], + ], + + 'redis' => [ + 'driver' => 'redis', + 'connection' => 'cache', + 'lock_connection' => 'default', + ], + + 'dynamodb' => [ + 'driver' => 'dynamodb', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), + 'endpoint' => env('DYNAMODB_ENDPOINT'), + ], + + 'octane' => [ + 'driver' => 'octane', + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Cache Key Prefix + |-------------------------------------------------------------------------- + | + | When utilizing the APC, database, memcached, Redis, or DynamoDB cache + | stores there might be other applications using the same cache. For + | that reason, you may prefix every cache key to avoid collisions. + | + */ + + 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'), + +]; diff --git a/projects/auth-with-passport/config/cors.php b/projects/auth-with-passport/config/cors.php new file mode 100644 index 0000000..df4ef51 --- /dev/null +++ b/projects/auth-with-passport/config/cors.php @@ -0,0 +1,36 @@ + ['*'], + + 'allowed_methods' => ['*'], + + 'allowed_origins' => [env('FRONTEND_URL', 'http://localhost:3000')], + + 'allowed_origins_patterns' => [], + + 'allowed_headers' => ['*'], + + 'exposed_headers' => [], + + 'max_age' => 0, + + 'supports_credentials' => true, + +]; diff --git a/projects/auth-with-passport/config/database.php b/projects/auth-with-passport/config/database.php new file mode 100644 index 0000000..f75f0d9 --- /dev/null +++ b/projects/auth-with-passport/config/database.php @@ -0,0 +1,153 @@ + env('DB_CONNECTION', 'mysql'), + + /* + |-------------------------------------------------------------------------- + | Database Connections + |-------------------------------------------------------------------------- + | + | Here are each of the database connections setup for your application. + | Of course, examples of configuring each database platform that is + | supported by Laravel is shown below to make development simple. + | + | + | All database work in Laravel is done through the PHP PDO facilities + | so make sure you have the driver for your particular database of + | choice installed on your machine before you begin development. + | + */ + + 'connections' => [ + + 'sqlite' => [ + 'driver' => 'sqlite', + 'url' => env('DATABASE_URL'), + 'database' => env('DB_DATABASE', database_path('database.sqlite')), + 'prefix' => '', + 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), + ], + + 'mysql' => [ + 'driver' => 'mysql', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => true, + 'engine' => null, + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [], + ], + + 'pgsql' => [ + 'driver' => 'pgsql', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '5432'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => 'utf8', + 'prefix' => '', + 'prefix_indexes' => true, + 'search_path' => 'public', + 'sslmode' => 'prefer', + ], + + 'sqlsrv' => [ + 'driver' => 'sqlsrv', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', '1433'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => 'utf8', + 'prefix' => '', + 'prefix_indexes' => true, + // 'encrypt' => env('DB_ENCRYPT', 'yes'), + // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Migration Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the migrations that have already run for + | your application. Using this information, we can determine which of + | the migrations on disk haven't actually been run in the database. + | + */ + + 'migrations' => 'migrations', + + /* + |-------------------------------------------------------------------------- + | Redis Databases + |-------------------------------------------------------------------------- + | + | Redis is an open source, fast, and advanced key-value store that also + | provides a richer body of commands than a typical key-value system + | such as APC or Memcached. Laravel makes it easy to dig right in. + | + */ + + 'redis' => [ + + 'client' => env('REDIS_CLIENT', 'phpredis'), + + 'options' => [ + 'cluster' => env('REDIS_CLUSTER', 'redis'), + 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), + ], + + 'default' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'username' => env('REDIS_USERNAME'), + 'password' => env('REDIS_PASSWORD'), + 'port' => env('REDIS_PORT', '6379'), + 'database' => env('REDIS_DB', '0'), + ], + + 'cache' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'username' => env('REDIS_USERNAME'), + 'password' => env('REDIS_PASSWORD'), + 'port' => env('REDIS_PORT', '6379'), + 'database' => env('REDIS_CACHE_DB', '1'), + ], + + ], + +]; diff --git a/projects/auth-with-passport/config/filesystems.php b/projects/auth-with-passport/config/filesystems.php new file mode 100644 index 0000000..d307268 --- /dev/null +++ b/projects/auth-with-passport/config/filesystems.php @@ -0,0 +1,78 @@ + env('FILESYSTEM_DISK', 'local'), + + /* + |-------------------------------------------------------------------------- + | Filesystem Disks + |-------------------------------------------------------------------------- + | + | Here you may configure as many filesystem "disks" as you wish, and you + | may even configure multiple disks of the same driver. Defaults have + | been set up for each driver as an example of the required values. + | + | Supported Drivers: "local", "ftp", "sftp", "s3" + | + */ + + 'disks' => [ + + 'local' => [ + 'driver' => 'local', + 'root' => storage_path('app'), + 'throw' => false, + ], + + 'public' => [ + 'driver' => 'local', + 'root' => storage_path('app/public'), + 'url' => env('APP_URL').'/storage', + 'visibility' => 'public', + 'throw' => false, + ], + + 's3' => [ + 'driver' => 's3', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('AWS_DEFAULT_REGION'), + 'bucket' => env('AWS_BUCKET'), + 'url' => env('AWS_URL'), + 'endpoint' => env('AWS_ENDPOINT'), + 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), + 'throw' => false, + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Symbolic Links + |-------------------------------------------------------------------------- + | + | Here you may configure the symbolic links that will be created when the + | `storage:link` Artisan command is executed. The array keys should be + | the locations of the links and the values should be their targets. + | + */ + + 'links' => [ + public_path('storage') => storage_path('app/public'), + ], + +]; diff --git a/projects/auth-with-passport/config/hashing.php b/projects/auth-with-passport/config/hashing.php new file mode 100644 index 0000000..41cba61 --- /dev/null +++ b/projects/auth-with-passport/config/hashing.php @@ -0,0 +1,54 @@ + 'bcrypt', + + /* + |-------------------------------------------------------------------------- + | Bcrypt Options + |-------------------------------------------------------------------------- + | + | Here you may specify the configuration options that should be used when + | passwords are hashed using the Bcrypt algorithm. This will allow you + | to control the amount of time it takes to hash the given password. + | + */ + + 'bcrypt' => [ + 'rounds' => env('BCRYPT_ROUNDS', 10), + ], + + /* + |-------------------------------------------------------------------------- + | Argon Options + |-------------------------------------------------------------------------- + | + | Here you may specify the configuration options that should be used when + | passwords are hashed using the Argon algorithm. These will allow you + | to control the amount of time it takes to hash the given password. + | + */ + + 'argon' => [ + 'memory' => 65536, + 'threads' => 1, + 'time' => 4, + ], + +]; diff --git a/projects/auth-with-passport/config/headers.php b/projects/auth-with-passport/config/headers.php new file mode 100644 index 0000000..f6a5a69 --- /dev/null +++ b/projects/auth-with-passport/config/headers.php @@ -0,0 +1,22 @@ + [ + 'X-Powered-By', + 'x-powered-by', + 'Server', + 'server', + ], + + 'referrer-policy' => 'no-referrer-when-downgrade', + + 'strict-transport-security' => 'max-age=31536000; includeSubDomains', + + 'certificate-transparency' => 'enforce, max-age=30', + + 'permissions-policy' => 'autoplay=(self), camera=(), encrypted-media=(self), fullscreen=(), geolocation=(self), gyroscope=(self), magnetometer=(), microphone=(), midi=(), payment=(), sync-xhr=(self), usb=()', + + 'content-type-options' => 'nosniff', +]; diff --git a/projects/auth-with-passport/config/logging.php b/projects/auth-with-passport/config/logging.php new file mode 100644 index 0000000..e20f363 --- /dev/null +++ b/projects/auth-with-passport/config/logging.php @@ -0,0 +1,125 @@ + env('LOG_CHANNEL', 'stack'), + + /* + |-------------------------------------------------------------------------- + | Deprecations Log Channel + |-------------------------------------------------------------------------- + | + | This option controls the log channel that should be used to log warnings + | regarding deprecated PHP and library features. This allows you to get + | your application ready for upcoming major versions of dependencies. + | + */ + + 'deprecations' => [ + 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), + 'trace' => false, + ], + + /* + |-------------------------------------------------------------------------- + | Log Channels + |-------------------------------------------------------------------------- + | + | Here you may configure the log channels for your application. Out of + | the box, Laravel uses the Monolog PHP logging library. This gives + | you a variety of powerful log handlers / formatters to utilize. + | + | Available Drivers: "single", "daily", "slack", "syslog", + | "errorlog", "monolog", + | "custom", "stack" + | + */ + + 'channels' => [ + 'stack' => [ + 'driver' => 'stack', + 'channels' => ['single'], + 'ignore_exceptions' => false, + ], + + 'single' => [ + 'driver' => 'single', + 'path' => storage_path('logs/laravel.log'), + 'level' => env('LOG_LEVEL', 'debug'), + ], + + 'daily' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/laravel.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'days' => 14, + ], + + 'slack' => [ + 'driver' => 'slack', + 'url' => env('LOG_SLACK_WEBHOOK_URL'), + 'username' => 'Laravel Log', + 'emoji' => ':boom:', + 'level' => env('LOG_LEVEL', 'critical'), + ], + + 'papertrail' => [ + 'driver' => 'monolog', + 'level' => env('LOG_LEVEL', 'debug'), + 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), + 'handler_with' => [ + 'host' => env('PAPERTRAIL_URL'), + 'port' => env('PAPERTRAIL_PORT'), + 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), + ], + ], + + 'stderr' => [ + 'driver' => 'monolog', + 'level' => env('LOG_LEVEL', 'debug'), + 'handler' => StreamHandler::class, + 'formatter' => env('LOG_STDERR_FORMATTER'), + 'with' => [ + 'stream' => 'php://stderr', + ], + ], + + 'syslog' => [ + 'driver' => 'syslog', + 'level' => env('LOG_LEVEL', 'debug'), + 'facility' => LOG_USER, + ], + + 'errorlog' => [ + 'driver' => 'errorlog', + 'level' => env('LOG_LEVEL', 'debug'), + ], + + 'null' => [ + 'driver' => 'monolog', + 'handler' => NullHandler::class, + ], + + 'emergency' => [ + 'path' => storage_path('logs/laravel.log'), + ], + ], + +]; diff --git a/projects/auth-with-passport/config/mail.php b/projects/auth-with-passport/config/mail.php new file mode 100644 index 0000000..1cb9684 --- /dev/null +++ b/projects/auth-with-passport/config/mail.php @@ -0,0 +1,126 @@ + env('MAIL_MAILER', 'smtp'), + + /* + |-------------------------------------------------------------------------- + | Mailer Configurations + |-------------------------------------------------------------------------- + | + | Here you may configure all of the mailers used by your application plus + | their respective settings. Several examples have been configured for + | you and you are free to add your own as your application requires. + | + | Laravel supports a variety of mail "transport" drivers to be used while + | sending an e-mail. You will specify which one you are using for your + | mailers below. You are free to add additional mailers as required. + | + | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", + | "postmark", "log", "array", "failover" + | + */ + + 'mailers' => [ + 'smtp' => [ + 'transport' => 'smtp', + 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), + 'port' => env('MAIL_PORT', 587), + 'encryption' => env('MAIL_ENCRYPTION', 'tls'), + 'username' => env('MAIL_USERNAME'), + 'password' => env('MAIL_PASSWORD'), + 'timeout' => null, + 'local_domain' => env('MAIL_EHLO_DOMAIN'), + ], + + 'ses' => [ + 'transport' => 'ses', + ], + + 'mailgun' => [ + 'transport' => 'mailgun', + // 'client' => [ + // 'timeout' => 5, + // ], + ], + + 'postmark' => [ + 'transport' => 'postmark', + // 'client' => [ + // 'timeout' => 5, + // ], + ], + + 'sendmail' => [ + 'transport' => 'sendmail', + 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), + ], + + 'log' => [ + 'transport' => 'log', + 'channel' => env('MAIL_LOG_CHANNEL'), + ], + + 'array' => [ + 'transport' => 'array', + ], + + 'failover' => [ + 'transport' => 'failover', + 'mailers' => [ + 'smtp', + 'log', + ], + ], + ], + + /* + |-------------------------------------------------------------------------- + | Global "From" Address + |-------------------------------------------------------------------------- + | + | You may wish for all e-mails sent by your application to be sent from + | the same address. Here, you may specify a name and address that is + | used globally for all e-mails that are sent by your application. + | + */ + + 'from' => [ + 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), + 'name' => env('MAIL_FROM_NAME', 'Example'), + ], + + /* + |-------------------------------------------------------------------------- + | Markdown Mail Settings + |-------------------------------------------------------------------------- + | + | If you are using Markdown based email rendering, you may configure your + | theme and component paths here, allowing you to customize the design + | of the emails. Or, you may simply stick with the Laravel defaults! + | + */ + + 'markdown' => [ + 'theme' => 'default', + + 'paths' => [ + resource_path('views/vendor/mail'), + ], + ], + +]; diff --git a/projects/auth-with-passport/config/passport.php b/projects/auth-with-passport/config/passport.php new file mode 100644 index 0000000..9aa5fe8 --- /dev/null +++ b/projects/auth-with-passport/config/passport.php @@ -0,0 +1,62 @@ + 'web', + + /* + |-------------------------------------------------------------------------- + | Encryption Keys + |-------------------------------------------------------------------------- + | + | Passport uses encryption keys while generating secure access tokens for + | your application. By default, the keys are stored as local files but + | can be set via environment variables when that is more convenient. + | + */ + + 'private_key' => env('PASSPORT_PRIVATE_KEY'), + + 'public_key' => env('PASSPORT_PUBLIC_KEY'), + + /* + |-------------------------------------------------------------------------- + | Client UUIDs + |-------------------------------------------------------------------------- + | + | By default, Passport uses auto-incrementing primary keys when assigning + | IDs to clients. However, if Passport is installed using the provided + | --uuids switch, this will be set to "true" and UUIDs will be used. + | + */ + + 'client_uuids' => true, + + /* + |-------------------------------------------------------------------------- + | Personal Access Client + |-------------------------------------------------------------------------- + | + | If you enable client hashing, you should set the personal access client + | ID and unhashed secret within your environment file. The values will + | get used while issuing fresh personal access tokens to your users. + | + */ + + 'personal_access_client' => [ + 'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'), + 'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'), + ], + +]; diff --git a/projects/auth-with-passport/config/queue.php b/projects/auth-with-passport/config/queue.php new file mode 100644 index 0000000..485dd98 --- /dev/null +++ b/projects/auth-with-passport/config/queue.php @@ -0,0 +1,95 @@ + env('QUEUE_CONNECTION', 'sync'), + + /* + |-------------------------------------------------------------------------- + | Queue Connections + |-------------------------------------------------------------------------- + | + | Here you may configure the connection information for each server that + | is used by your application. A default configuration has been added + | for each back-end shipped with Laravel. You are free to add more. + | + | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" + | + */ + + 'connections' => [ + + 'sync' => [ + 'driver' => 'sync', + ], + + 'database' => [ + 'driver' => 'database', + 'table' => 'jobs', + 'queue' => 'default', + 'retry_after' => 90, + 'after_commit' => false, + ], + + 'beanstalkd' => [ + 'driver' => 'beanstalkd', + 'host' => 'localhost', + 'queue' => 'default', + 'retry_after' => 90, + 'block_for' => 0, + 'after_commit' => false, + ], + + 'sqs' => [ + 'driver' => 'sqs', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), + 'queue' => env('SQS_QUEUE', 'default'), + 'suffix' => env('SQS_SUFFIX'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + 'after_commit' => false, + ], + + 'redis' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => env('REDIS_QUEUE', 'default'), + 'retry_after' => 90, + 'block_for' => null, + 'after_commit' => false, + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Failed Queue Jobs + |-------------------------------------------------------------------------- + | + | These options configure the behavior of failed queue job logging so you + | can control which database and table are used to store the jobs that + | have failed. You may change them to any database / table you wish. + | + */ + + 'failed' => [ + 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), + 'database' => env('DB_CONNECTION', 'mysql'), + 'table' => 'failed_jobs', + ], + +]; diff --git a/projects/auth-with-passport/config/sanctum.php b/projects/auth-with-passport/config/sanctum.php new file mode 100644 index 0000000..7f38290 --- /dev/null +++ b/projects/auth-with-passport/config/sanctum.php @@ -0,0 +1,54 @@ + explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( + '%s%s%s', + 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', + env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : '', + env('FRONTEND_URL') ? ','.parse_url(env('FRONTEND_URL'), PHP_URL_HOST) : '' + ))), + + /* + |-------------------------------------------------------------------------- + | Expiration Minutes + |-------------------------------------------------------------------------- + | + | This value controls the number of minutes until an issued token will be + | considered expired. If this value is null, personal access tokens do + | not expire. This won't tweak the lifetime of first-party sessions. + | + */ + + 'expiration' => null, + + /* + |-------------------------------------------------------------------------- + | Sanctum Middleware + |-------------------------------------------------------------------------- + | + | When authenticating your first-party SPA with Sanctum you may need to + | customize some of the middleware Sanctum uses while processing the + | request. You may change the middleware listed below as required. + | + */ + + 'middleware' => [ + 'verify_csrf_token' => \Core\Http\Middleware\VerifyCsrfToken::class, + 'encrypt_cookies' => \Core\Http\Middleware\EncryptCookies::class, + ], + +]; diff --git a/projects/auth-with-passport/config/services.php b/projects/auth-with-passport/config/services.php new file mode 100644 index 0000000..104826f --- /dev/null +++ b/projects/auth-with-passport/config/services.php @@ -0,0 +1,36 @@ + [ + 'domain' => env('MAILGUN_DOMAIN'), + 'secret' => env('MAILGUN_SECRET'), + 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), + 'scheme' => 'https', + ], + + 'postmark' => [ + 'token' => env('POSTMARK_TOKEN'), + ], + + 'ses' => [ + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + ], + +]; diff --git a/projects/auth-with-passport/config/session.php b/projects/auth-with-passport/config/session.php new file mode 100644 index 0000000..eeee93d --- /dev/null +++ b/projects/auth-with-passport/config/session.php @@ -0,0 +1,203 @@ + env('SESSION_DRIVER', 'file'), + + /* + |-------------------------------------------------------------------------- + | Session Lifetime + |-------------------------------------------------------------------------- + | + | Here you may specify the number of minutes that you wish the session + | to be allowed to remain idle before it expires. If you want them + | to immediately expire on the browser closing, set that option. + | + */ + + 'lifetime' => env('SESSION_LIFETIME', 120), + + 'expire_on_close' => false, + + /* + |-------------------------------------------------------------------------- + | Session Encryption + |-------------------------------------------------------------------------- + | + | This option allows you to easily specify that all of your session data + | should be encrypted before it is stored. All encryption will be run + | automatically by Laravel and you can use the Session like normal. + | + */ + + 'encrypt' => false, + + /* + |-------------------------------------------------------------------------- + | Session File Location + |-------------------------------------------------------------------------- + | + | When using the native session driver, we need a location where session + | files may be stored. A default has been set for you but a different + | location may be specified. This is only needed for file sessions. + | + */ + + 'files' => storage_path('framework/sessions'), + + /* + |-------------------------------------------------------------------------- + | Session Database Connection + |-------------------------------------------------------------------------- + | + | When using the "database" or "redis" session drivers, you may specify a + | connection that should be used to manage these sessions. This should + | correspond to a connection in your database configuration options. + | + */ + + 'connection' => env('SESSION_CONNECTION'), + + /* + |-------------------------------------------------------------------------- + | Session Database Table + |-------------------------------------------------------------------------- + | + | When using the "database" session driver, you may specify the table we + | should use to manage the sessions. Of course, a sensible default is + | provided for you; however, you are free to change this as needed. + | + */ + + 'table' => 'sessions', + + /* + |-------------------------------------------------------------------------- + | Session Cache Store + |-------------------------------------------------------------------------- + | + | While using one of the framework's cache driven session backends you may + | list a cache store that should be used for these sessions. This value + | must match with one of the application's configured cache "stores". + | + | Affects: "apc", "dynamodb", "memcached", "redis" + | + */ + + 'store' => env('SESSION_STORE'), + + /* + |-------------------------------------------------------------------------- + | Session Sweeping Lottery + |-------------------------------------------------------------------------- + | + | Some session drivers must manually sweep their storage location to get + | rid of old sessions from storage. Here are the chances that it will + | happen on a given request. By default, the odds are 2 out of 100. + | + */ + + 'lottery' => [2, 100], + + /* + |-------------------------------------------------------------------------- + | Session Cookie Name + |-------------------------------------------------------------------------- + | + | Here you may change the name of the cookie used to identify a session + | instance by ID. The name specified here will get used every time a + | new session cookie is created by the framework for every driver. + | + */ + + 'cookie' => env( + 'SESSION_COOKIE', + Str::slug(env('APP_NAME', 'laravel'), '_').'_session' + ), + + /* + |-------------------------------------------------------------------------- + | Session Cookie Path + |-------------------------------------------------------------------------- + | + | The session cookie path determines the path for which the cookie will + | be regarded as available. Typically, this will be the root path of + | your application but you are free to change this when necessary. + | + */ + + 'path' => '/', + + /* + |-------------------------------------------------------------------------- + | Session Cookie Domain + |-------------------------------------------------------------------------- + | + | Here you may change the domain of the cookie used to identify a session + | in your application. This will determine which domains the cookie is + | available to in your application. A sensible default has been set. + | + */ + + 'domain' => env('SESSION_DOMAIN'), + + /* + |-------------------------------------------------------------------------- + | HTTPS Only Cookies + |-------------------------------------------------------------------------- + | + | By setting this option to true, session cookies will only be sent back + | to the server if the browser has a HTTPS connection. This will keep + | the cookie from being sent to you when it can't be done securely. + | + */ + + 'secure' => env('SESSION_SECURE_COOKIE'), + + /* + |-------------------------------------------------------------------------- + | HTTP Access Only + |-------------------------------------------------------------------------- + | + | Setting this value to true will prevent JavaScript from accessing the + | value of the cookie and the cookie will only be accessible through + | the HTTP protocol. You are free to modify this option if needed. + | + */ + + 'http_only' => true, + + /* + |-------------------------------------------------------------------------- + | Same-Site Cookies + |-------------------------------------------------------------------------- + | + | This option determines how your cookies behave when cross-site requests + | take place, and can be used to mitigate CSRF attacks. By default, we + | will set this value to "lax" since this is a secure default value. + | + | Supported: "lax", "strict", "none", null + | + */ + + 'same_site' => 'lax', + +]; diff --git a/projects/auth-with-passport/config/treblle.php b/projects/auth-with-passport/config/treblle.php new file mode 100644 index 0000000..7f6f900 --- /dev/null +++ b/projects/auth-with-passport/config/treblle.php @@ -0,0 +1,36 @@ + env('TREBLLE_API_KEY'), + + /* + * A valid Treblle project ID. Create your first project on https://treblle.com/ + */ + 'project_id' => env('TREBLLE_PROJECT_ID'), + + /* + * Define which environments should Treblle ignore and not monitor + */ + 'ignored_environments' => env('TREBLLE_IGNORED_ENV', 'dev,test'), + + /* + * Define which fields should be masked before leaving the server + */ + 'masked_fields' => [ + 'password', + 'pwd', + 'secret', + 'password_confirmation', + 'cc', + 'card_number', + 'ccv', + 'ssn', + 'credit_score', + 'api_key', + ], +]; diff --git a/projects/auth-with-passport/config/view.php b/projects/auth-with-passport/config/view.php new file mode 100644 index 0000000..d9c90c0 --- /dev/null +++ b/projects/auth-with-passport/config/view.php @@ -0,0 +1,38 @@ + [ + resource_path('views'), + ], + + /* + |-------------------------------------------------------------------------- + | Compiled View Path + |-------------------------------------------------------------------------- + | + | This option determines where all the compiled Blade templates will be + | stored for your application. Typically, this is within the storage + | directory. However, as usual, you are free to change this value. + | + */ + + 'compiled' => env( + 'VIEW_COMPILED_PATH', + realpath(storage_path('framework/views')) + ), + +]; diff --git a/projects/auth-with-passport/core/Console/Kernel.php b/projects/auth-with-passport/core/Console/Kernel.php new file mode 100644 index 0000000..09b7548 --- /dev/null +++ b/projects/auth-with-passport/core/Console/Kernel.php @@ -0,0 +1,25 @@ +load( + paths: [ + __DIR__ . '/../app/Console/Commands', + ], + ); + } +} diff --git a/projects/auth-with-passport/core/Exceptions/Handler.php b/projects/auth-with-passport/core/Exceptions/Handler.php new file mode 100644 index 0000000..2be409d --- /dev/null +++ b/projects/auth-with-passport/core/Exceptions/Handler.php @@ -0,0 +1,28 @@ +reportable(function (Throwable $e) { + // + }); + } +} diff --git a/projects/auth-with-passport/core/Http/Controllers/Controller.php b/projects/auth-with-passport/core/Http/Controllers/Controller.php new file mode 100644 index 0000000..375b591 --- /dev/null +++ b/projects/auth-with-passport/core/Http/Controllers/Controller.php @@ -0,0 +1,15 @@ + [], + + 'api' => [ + ThrottleRequests::class.':api', + ContentTypeMiddleware::class, + CacheHeaders::class, + RemoveHeaders::class, + StrictTransportSecurity::class, + SetReferrerPolicy::class, + PermissionsPolicy::class, + ContentTypeOptions::class, + CertificateTransparencyPolicy::class, + XFrameOptionMiddleware::class, + ], + ]; + + protected $middlewareAliases = [ + 'auth' => Authenticate::class, + 'cache.headers' => SetCacheHeaders::class, + 'can' => Authorize::class, + 'password.confirm' => RequirePassword::class, + 'signed' => ValidateSignature::class, + 'throttle' => ThrottleRequests::class, + 'verified' => EnsureEmailIsVerified::class, + ]; +} diff --git a/projects/auth-with-passport/core/Providers/AppServiceProvider.php b/projects/auth-with-passport/core/Providers/AppServiceProvider.php new file mode 100644 index 0000000..8f74df1 --- /dev/null +++ b/projects/auth-with-passport/core/Providers/AppServiceProvider.php @@ -0,0 +1,15 @@ +registerPolicies(); + } +} diff --git a/projects/auth-with-passport/core/Providers/BroadcastServiceProvider.php b/projects/auth-with-passport/core/Providers/BroadcastServiceProvider.php new file mode 100644 index 0000000..f379f20 --- /dev/null +++ b/projects/auth-with-passport/core/Providers/BroadcastServiceProvider.php @@ -0,0 +1,17 @@ + [ + SendEmailVerificationNotification::class, + ], + ]; +} diff --git a/projects/auth-with-passport/core/Providers/RouteServiceProvider.php b/projects/auth-with-passport/core/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..85312e2 --- /dev/null +++ b/projects/auth-with-passport/core/Providers/RouteServiceProvider.php @@ -0,0 +1,39 @@ +configureRateLimiting(); + + $this->routes(static function (): void { + Route::middleware('api') + ->as('api:') + ->group( + base_path('routes/api/routes.php') + ); + }); + } + + protected function configureRateLimiting(): void + { + RateLimiter::for( + name: 'api', + callback: static fn (Request $request): Limit => Limit::perMinute( + maxAttempts: 60, + )->by( + key: $request->user()?->id ?: $request->ip(), + ), + ); + } +} diff --git a/projects/auth-with-passport/database/.gitignore b/projects/auth-with-passport/database/.gitignore new file mode 100644 index 0000000..9b19b93 --- /dev/null +++ b/projects/auth-with-passport/database/.gitignore @@ -0,0 +1 @@ +*.sqlite* diff --git a/projects/auth-with-passport/database/factories/UserFactory.php b/projects/auth-with-passport/database/factories/UserFactory.php new file mode 100644 index 0000000..75fc148 --- /dev/null +++ b/projects/auth-with-passport/database/factories/UserFactory.php @@ -0,0 +1,35 @@ + $this->faker->name(), + 'email' => $this->faker->unique()->safeEmail(), + 'email_verified_at' => now(), + 'password' => Hash::make( + value: 'password', + ), + ]; + } + + public function unverified(): UserFactory + { + return $this->state( + state: fn (array $attributes): array => [ + 'email_verified_at' => null, + ], + ); + } +} diff --git a/projects/auth-with-passport/database/migrations/2014_10_12_000000_create_users_table.php b/projects/auth-with-passport/database/migrations/2014_10_12_000000_create_users_table.php new file mode 100644 index 0000000..6a9f82d --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2014_10_12_000000_create_users_table.php @@ -0,0 +1,28 @@ +uuid('id')->primary(); + + $table->string('name'); + $table->string('email')->unique(); + $table->string('password'); + + $table->timestamp('email_verified_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('users'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php b/projects/auth-with-passport/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php new file mode 100644 index 0000000..f9d43b1 --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php @@ -0,0 +1,23 @@ +string('email')->primary(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + }); + } + + public function down(): void + { + Schema::dropIfExists('password_reset_tokens'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php b/projects/auth-with-passport/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php new file mode 100644 index 0000000..247a167 --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php @@ -0,0 +1,31 @@ +string('id', 100)->primary(); + $table->unsignedBigInteger('user_id')->index(); + $table->uuid('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'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/projects/auth-with-passport/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php new file mode 100644 index 0000000..c6347d1 --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php @@ -0,0 +1,34 @@ +string('id', 100)->primary(); + // $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->uuid('user_id')->nullable()->index(); + $table->uuid('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'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php b/projects/auth-with-passport/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php new file mode 100644 index 0000000..b007904 --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php @@ -0,0 +1,29 @@ +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'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2016_06_01_000004_create_oauth_clients_table.php b/projects/auth-with-passport/database/migrations/2016_06_01_000004_create_oauth_clients_table.php new file mode 100644 index 0000000..8e437ea --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2016_06_01_000004_create_oauth_clients_table.php @@ -0,0 +1,35 @@ +uuid('id')->primary(); + $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'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php b/projects/auth-with-passport/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php new file mode 100644 index 0000000..15398c9 --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php @@ -0,0 +1,28 @@ +bigIncrements('id'); + $table->uuid('client_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_personal_access_clients'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/projects/auth-with-passport/database/migrations/2019_08_19_000000_create_failed_jobs_table.php new file mode 100644 index 0000000..4af0906 --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -0,0 +1,27 @@ +id(); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + public function down(): void + { + Schema::dropIfExists('failed_jobs'); + } +}; diff --git a/projects/auth-with-passport/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/projects/auth-with-passport/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php new file mode 100644 index 0000000..81df00e --- /dev/null +++ b/projects/auth-with-passport/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -0,0 +1,30 @@ +id(); + + $table->uuidMorphs('tokenable'); + $table->string('name'); + $table->string('token', 64)->unique(); + $table->text('abilities')->nullable(); + + $table->timestamp('last_used_at')->nullable(); + $table->timestamp('expires_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('personal_access_tokens'); + } +}; diff --git a/projects/auth-with-passport/database/seeders/DatabaseSeeder.php b/projects/auth-with-passport/database/seeders/DatabaseSeeder.php new file mode 100644 index 0000000..985b5b7 --- /dev/null +++ b/projects/auth-with-passport/database/seeders/DatabaseSeeder.php @@ -0,0 +1,19 @@ +create([ + 'name' => 'Arthur Monney', + 'email' => 'monneylobe@gmail.com', + ]); + } +} diff --git a/projects/auth-with-passport/lang/en/auth.php b/projects/auth-with-passport/lang/en/auth.php new file mode 100644 index 0000000..e2de2ac --- /dev/null +++ b/projects/auth-with-passport/lang/en/auth.php @@ -0,0 +1,22 @@ + 'These credentials do not match our records.', + 'password' => 'The provided password is incorrect.', + 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', + +]; diff --git a/projects/auth-with-passport/lang/en/messages.php b/projects/auth-with-passport/lang/en/messages.php new file mode 100644 index 0000000..376c7e3 --- /dev/null +++ b/projects/auth-with-passport/lang/en/messages.php @@ -0,0 +1,9 @@ + 'Welcome to Laravel API Skeleton', + +]; diff --git a/projects/auth-with-passport/lang/en/pagination.php b/projects/auth-with-passport/lang/en/pagination.php new file mode 100644 index 0000000..f03c42c --- /dev/null +++ b/projects/auth-with-passport/lang/en/pagination.php @@ -0,0 +1,21 @@ + '« Previous', + 'next' => 'Next »', + +]; diff --git a/projects/auth-with-passport/lang/en/passwords.php b/projects/auth-with-passport/lang/en/passwords.php new file mode 100644 index 0000000..4309232 --- /dev/null +++ b/projects/auth-with-passport/lang/en/passwords.php @@ -0,0 +1,24 @@ + 'Your password has been reset.', + 'sent' => 'We have emailed your password reset link.', + 'throttled' => 'Please wait before retrying.', + 'token' => 'This password reset token is invalid.', + 'user' => "We can't find a user with that email address.", + +]; diff --git a/projects/auth-with-passport/lang/en/validation.php b/projects/auth-with-passport/lang/en/validation.php new file mode 100644 index 0000000..fd0ec4b --- /dev/null +++ b/projects/auth-with-passport/lang/en/validation.php @@ -0,0 +1,186 @@ + 'The :attribute field must be accepted.', + 'accepted_if' => 'The :attribute field must be accepted when :other is :value.', + 'active_url' => 'The :attribute field must be a valid URL.', + 'after' => 'The :attribute field must be a date after :date.', + 'after_or_equal' => 'The :attribute field must be a date after or equal to :date.', + 'alpha' => 'The :attribute field must only contain letters.', + 'alpha_dash' => 'The :attribute field must only contain letters, numbers, dashes, and underscores.', + 'alpha_num' => 'The :attribute field must only contain letters and numbers.', + 'array' => 'The :attribute field must be an array.', + 'ascii' => 'The :attribute field must only contain single-byte alphanumeric characters and symbols.', + 'before' => 'The :attribute field must be a date before :date.', + 'before_or_equal' => 'The :attribute field must be a date before or equal to :date.', + 'between' => [ + 'array' => 'The :attribute field must have between :min and :max items.', + 'file' => 'The :attribute field must be between :min and :max kilobytes.', + 'numeric' => 'The :attribute field must be between :min and :max.', + 'string' => 'The :attribute field must be between :min and :max characters.', + ], + 'boolean' => 'The :attribute field must be true or false.', + 'confirmed' => 'The :attribute field confirmation does not match.', + 'current_password' => 'The password is incorrect.', + 'date' => 'The :attribute field must be a valid date.', + 'date_equals' => 'The :attribute field must be a date equal to :date.', + 'date_format' => 'The :attribute field must match the format :format.', + 'decimal' => 'The :attribute field must have :decimal decimal places.', + 'declined' => 'The :attribute field must be declined.', + 'declined_if' => 'The :attribute field must be declined when :other is :value.', + 'different' => 'The :attribute field and :other must be different.', + 'digits' => 'The :attribute field must be :digits digits.', + 'digits_between' => 'The :attribute field must be between :min and :max digits.', + 'dimensions' => 'The :attribute field has invalid image dimensions.', + 'distinct' => 'The :attribute field has a duplicate value.', + 'doesnt_end_with' => 'The :attribute field must not end with one of the following: :values.', + 'doesnt_start_with' => 'The :attribute field must not start with one of the following: :values.', + 'email' => 'The :attribute field must be a valid email address.', + 'ends_with' => 'The :attribute field must end with one of the following: :values.', + 'enum' => 'The selected :attribute is invalid.', + 'exists' => 'The selected :attribute is invalid.', + 'file' => 'The :attribute field must be a file.', + 'filled' => 'The :attribute field must have a value.', + 'gt' => [ + 'array' => 'The :attribute field must have more than :value items.', + 'file' => 'The :attribute field must be greater than :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than :value.', + 'string' => 'The :attribute field must be greater than :value characters.', + ], + 'gte' => [ + 'array' => 'The :attribute field must have :value items or more.', + 'file' => 'The :attribute field must be greater than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than or equal to :value.', + 'string' => 'The :attribute field must be greater than or equal to :value characters.', + ], + 'image' => 'The :attribute field must be an image.', + 'in' => 'The selected :attribute is invalid.', + 'in_array' => 'The :attribute field must exist in :other.', + 'integer' => 'The :attribute field must be an integer.', + 'ip' => 'The :attribute field must be a valid IP address.', + 'ipv4' => 'The :attribute field must be a valid IPv4 address.', + 'ipv6' => 'The :attribute field must be a valid IPv6 address.', + 'json' => 'The :attribute field must be a valid JSON string.', + 'lowercase' => 'The :attribute field must be lowercase.', + 'lt' => [ + 'array' => 'The :attribute field must have less than :value items.', + 'file' => 'The :attribute field must be less than :value kilobytes.', + 'numeric' => 'The :attribute field must be less than :value.', + 'string' => 'The :attribute field must be less than :value characters.', + ], + 'lte' => [ + 'array' => 'The :attribute field must not have more than :value items.', + 'file' => 'The :attribute field must be less than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be less than or equal to :value.', + 'string' => 'The :attribute field must be less than or equal to :value characters.', + ], + 'mac_address' => 'The :attribute field must be a valid MAC address.', + 'max' => [ + 'array' => 'The :attribute field must not have more than :max items.', + 'file' => 'The :attribute field must not be greater than :max kilobytes.', + 'numeric' => 'The :attribute field must not be greater than :max.', + 'string' => 'The :attribute field must not be greater than :max characters.', + ], + 'max_digits' => 'The :attribute field must not have more than :max digits.', + 'mimes' => 'The :attribute field must be a file of type: :values.', + 'mimetypes' => 'The :attribute field must be a file of type: :values.', + 'min' => [ + 'array' => 'The :attribute field must have at least :min items.', + 'file' => 'The :attribute field must be at least :min kilobytes.', + 'numeric' => 'The :attribute field must be at least :min.', + 'string' => 'The :attribute field must be at least :min characters.', + ], + 'min_digits' => 'The :attribute field must have at least :min digits.', + 'missing' => 'The :attribute field must be missing.', + 'missing_if' => 'The :attribute field must be missing when :other is :value.', + 'missing_unless' => 'The :attribute field must be missing unless :other is :value.', + 'missing_with' => 'The :attribute field must be missing when :values is present.', + 'missing_with_all' => 'The :attribute field must be missing when :values are present.', + 'multiple_of' => 'The :attribute field must be a multiple of :value.', + 'not_in' => 'The selected :attribute is invalid.', + 'not_regex' => 'The :attribute field format is invalid.', + 'numeric' => 'The :attribute field must be a number.', + 'password' => [ + 'letters' => 'The :attribute field must contain at least one letter.', + 'mixed' => 'The :attribute field must contain at least one uppercase and one lowercase letter.', + 'numbers' => 'The :attribute field must contain at least one number.', + 'symbols' => 'The :attribute field must contain at least one symbol.', + 'uncompromised' => 'The given :attribute has appeared in a data leak. Please choose a different :attribute.', + ], + 'present' => 'The :attribute field must be present.', + 'prohibited' => 'The :attribute field is prohibited.', + 'prohibited_if' => 'The :attribute field is prohibited when :other is :value.', + 'prohibited_unless' => 'The :attribute field is prohibited unless :other is in :values.', + 'prohibits' => 'The :attribute field prohibits :other from being present.', + 'regex' => 'The :attribute field format is invalid.', + 'required' => 'The :attribute field is required.', + 'required_array_keys' => 'The :attribute field must contain entries for: :values.', + 'required_if' => 'The :attribute field is required when :other is :value.', + 'required_if_accepted' => 'The :attribute field is required when :other is accepted.', + 'required_unless' => 'The :attribute field is required unless :other is in :values.', + 'required_with' => 'The :attribute field is required when :values is present.', + 'required_with_all' => 'The :attribute field is required when :values are present.', + 'required_without' => 'The :attribute field is required when :values is not present.', + 'required_without_all' => 'The :attribute field is required when none of :values are present.', + 'same' => 'The :attribute field must match :other.', + 'size' => [ + 'array' => 'The :attribute field must contain :size items.', + 'file' => 'The :attribute field must be :size kilobytes.', + 'numeric' => 'The :attribute field must be :size.', + 'string' => 'The :attribute field must be :size characters.', + ], + 'starts_with' => 'The :attribute field must start with one of the following: :values.', + 'string' => 'The :attribute field must be a string.', + 'timezone' => 'The :attribute field must be a valid timezone.', + 'unique' => 'The :attribute has already been taken.', + 'uploaded' => 'The :attribute failed to upload.', + 'uppercase' => 'The :attribute field must be uppercase.', + 'url' => 'The :attribute field must be a valid URL.', + 'ulid' => 'The :attribute field must be a valid ULID.', + 'uuid' => 'The :attribute field must be a valid UUID.', + + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap our attribute placeholder + | with something more reader friendly such as "E-Mail Address" instead + | of "email". This simply helps us make our message more expressive. + | + */ + + 'attributes' => [], + +]; diff --git a/projects/auth-with-passport/lang/fr/messages.php b/projects/auth-with-passport/lang/fr/messages.php new file mode 100644 index 0000000..5710fca --- /dev/null +++ b/projects/auth-with-passport/lang/fr/messages.php @@ -0,0 +1,9 @@ + 'Bienvenue sur Laravel API Skeleton', + +]; diff --git a/projects/auth-with-passport/phpstan.neon b/projects/auth-with-passport/phpstan.neon new file mode 100644 index 0000000..c0cb389 --- /dev/null +++ b/projects/auth-with-passport/phpstan.neon @@ -0,0 +1,21 @@ + +includes: + - ./vendor/nunomaduro/larastan/extension.neon + +parameters: + + paths: + - .core/ + - app/ + + level: 9 + + ignoreErrors: + + excludePaths: + - app/Http/Controllers/Auth/ + - app/Http/Middleware/ + - app/Http/Requests/Auth + - app/Providers/AuthServiceProvider.php + + checkMissingIterableValueType: false diff --git a/projects/auth-with-passport/phpunit.xml b/projects/auth-with-passport/phpunit.xml new file mode 100644 index 0000000..59b58db --- /dev/null +++ b/projects/auth-with-passport/phpunit.xml @@ -0,0 +1,31 @@ + + + + + ./tests/Unit + + + ./tests/Feature + + + + + ./app + + + + + + + + + + + + + diff --git a/projects/auth-with-passport/pint.json b/projects/auth-with-passport/pint.json new file mode 100644 index 0000000..bd6ec48 --- /dev/null +++ b/projects/auth-with-passport/pint.json @@ -0,0 +1,42 @@ +{ + "preset": "psr12", + "rules": { + "align_multiline_comment": true, + "array_indentation": true, + "array_syntax": true, + "blank_line_after_namespace": true, + "blank_line_after_opening_tag": true, + "combine_consecutive_issets": true, + "combine_consecutive_unsets": true, + "concat_space": true, + "declare_parentheses": true, + "declare_strict_types": true, + "explicit_string_variable": true, + "final_class": true, + "final_internal_class": false, + "fully_qualified_strict_types": true, + "global_namespace_import": { + "import_classes": true, + "import_constants": true, + "import_functions": true + }, + "is_null": true, + "lambda_not_used_import": true, + "logical_operators": true, + "mb_str_functions": true, + "method_chaining_indentation": true, + "modernize_strpos": true, + "new_with_braces": true, + "no_empty_comment": true, + "not_operator_with_space": true, + "ordered_traits": true, + "protected_to_private": true, + "simplified_if_return": true, + "strict_comparison": true, + "ternary_to_null_coalescing": true, + "trim_array_spaces": true, + "use_arrow_functions": true, + "void_return": true, + "yoda_style": true + } +} diff --git a/projects/auth-with-passport/public/.htaccess b/projects/auth-with-passport/public/.htaccess new file mode 100644 index 0000000..3aec5e2 --- /dev/null +++ b/projects/auth-with-passport/public/.htaccess @@ -0,0 +1,21 @@ + + + Options -MultiViews -Indexes + + + RewriteEngine On + + # Handle Authorization Header + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + # Redirect Trailing Slashes If Not A Folder... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_URI} (.+)/$ + RewriteRule ^ %1 [L,R=301] + + # Send Requests To Front Controller... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [L] + diff --git a/projects/auth-with-passport/public/favicon.ico b/projects/auth-with-passport/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/projects/auth-with-passport/public/index.php b/projects/auth-with-passport/public/index.php new file mode 100644 index 0000000..0765415 --- /dev/null +++ b/projects/auth-with-passport/public/index.php @@ -0,0 +1,57 @@ +make(Kernel::class); + +$response = $kernel->handle( + $request = Request::capture() +)->send(); + +$kernel->terminate($request, $response); diff --git a/projects/auth-with-passport/public/robots.txt b/projects/auth-with-passport/public/robots.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/projects/auth-with-passport/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/projects/auth-with-passport/resources/views/.gitkeep b/projects/auth-with-passport/resources/views/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/projects/auth-with-passport/resources/views/.gitkeep @@ -0,0 +1 @@ + diff --git a/projects/auth-with-passport/routes/api/routes.php b/projects/auth-with-passport/routes/api/routes.php new file mode 100644 index 0000000..eee66aa --- /dev/null +++ b/projects/auth-with-passport/routes/api/routes.php @@ -0,0 +1,12 @@ +as('v1:')->group( + base_path('routes/api/v1/api.php'), +); diff --git a/projects/auth-with-passport/routes/api/v1/api.php b/projects/auth-with-passport/routes/api/v1/api.php new file mode 100644 index 0000000..c5946a8 --- /dev/null +++ b/projects/auth-with-passport/routes/api/v1/api.php @@ -0,0 +1,18 @@ + ['message' => 'Welcome to the API version 1.0 !'])->name('home'); + +Route::controller(AuthController::class)->group(function() { + Route::post('/register', 'register'); + Route::post('/login', 'login'); + + Route::middleware('auth:api')->group(function (){ + Route::get('/user', 'getUser'); + Route::post('/logout', 'logout'); + }); +}); diff --git a/projects/auth-with-passport/routes/sockets/routes.php b/projects/auth-with-passport/routes/sockets/routes.php new file mode 100644 index 0000000..f2635d0 --- /dev/null +++ b/projects/auth-with-passport/routes/sockets/routes.php @@ -0,0 +1,11 @@ + (int) $user->getKey() === $id +); diff --git a/projects/auth-with-passport/storage/app/.gitignore b/projects/auth-with-passport/storage/app/.gitignore new file mode 100644 index 0000000..8f4803c --- /dev/null +++ b/projects/auth-with-passport/storage/app/.gitignore @@ -0,0 +1,3 @@ +* +!public/ +!.gitignore diff --git a/projects/auth-with-passport/storage/app/public/.gitignore b/projects/auth-with-passport/storage/app/public/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/projects/auth-with-passport/storage/app/public/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/projects/auth-with-passport/storage/framework/.gitignore b/projects/auth-with-passport/storage/framework/.gitignore new file mode 100644 index 0000000..05c4471 --- /dev/null +++ b/projects/auth-with-passport/storage/framework/.gitignore @@ -0,0 +1,9 @@ +compiled.php +config.php +down +events.scanned.php +maintenance.php +routes.php +routes.scanned.php +schedule-* +services.json diff --git a/projects/auth-with-passport/storage/framework/cache/.gitignore b/projects/auth-with-passport/storage/framework/cache/.gitignore new file mode 100644 index 0000000..01e4a6c --- /dev/null +++ b/projects/auth-with-passport/storage/framework/cache/.gitignore @@ -0,0 +1,3 @@ +* +!data/ +!.gitignore diff --git a/projects/auth-with-passport/storage/framework/cache/data/.gitignore b/projects/auth-with-passport/storage/framework/cache/data/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/projects/auth-with-passport/storage/framework/cache/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/projects/auth-with-passport/storage/framework/sessions/.gitignore b/projects/auth-with-passport/storage/framework/sessions/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/projects/auth-with-passport/storage/framework/sessions/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/projects/auth-with-passport/storage/framework/testing/.gitignore b/projects/auth-with-passport/storage/framework/testing/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/projects/auth-with-passport/storage/framework/testing/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/projects/auth-with-passport/storage/framework/views/.gitignore b/projects/auth-with-passport/storage/framework/views/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/projects/auth-with-passport/storage/framework/views/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/projects/auth-with-passport/storage/logs/.gitignore b/projects/auth-with-passport/storage/logs/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/projects/auth-with-passport/storage/logs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/projects/auth-with-passport/stubs/cast.stub b/projects/auth-with-passport/stubs/cast.stub new file mode 100644 index 0000000..2a91141 --- /dev/null +++ b/projects/auth-with-passport/stubs/cast.stub @@ -0,0 +1,31 @@ + $attributes + */ + public function get(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } + + /** + * Prepare the given value for storage. + * + * @param array $attributes + */ + public function set(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } +} diff --git a/projects/auth-with-passport/stubs/console.stub b/projects/auth-with-passport/stubs/console.stub new file mode 100644 index 0000000..ccc30e5 --- /dev/null +++ b/projects/auth-with-passport/stubs/console.stub @@ -0,0 +1,19 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/projects/auth-with-passport/stubs/factory.stub b/projects/auth-with-passport/stubs/factory.stub new file mode 100644 index 0000000..b5d39f5 --- /dev/null +++ b/projects/auth-with-passport/stubs/factory.stub @@ -0,0 +1,19 @@ + + */ + public function via(object $notifiable): array + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + return (new MailMessage)->markdown('{{ view }}'); + } + + /** + * Get the array representation of the notification. + * + * @return array + */ + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +} diff --git a/projects/auth-with-passport/stubs/middleware.stub b/projects/auth-with-passport/stubs/middleware.stub new file mode 100644 index 0000000..76b7b53 --- /dev/null +++ b/projects/auth-with-passport/stubs/middleware.stub @@ -0,0 +1,17 @@ +ulid('id')->primary(); + + // + + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('{{ table }}'); + } +}; diff --git a/projects/auth-with-passport/stubs/migration.stub b/projects/auth-with-passport/stubs/migration.stub new file mode 100644 index 0000000..62a5c4a --- /dev/null +++ b/projects/auth-with-passport/stubs/migration.stub @@ -0,0 +1,20 @@ +line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +} diff --git a/projects/auth-with-passport/stubs/policy.stub b/projects/auth-with-passport/stubs/policy.stub new file mode 100644 index 0000000..fbf7535 --- /dev/null +++ b/projects/auth-with-passport/stubs/policy.stub @@ -0,0 +1,47 @@ + + */ + public function toArray(Request $request): array + { + return parent::toArray($request); + } +} diff --git a/projects/auth-with-passport/stubs/rule.stub b/projects/auth-with-passport/stubs/rule.stub new file mode 100644 index 0000000..1028273 --- /dev/null +++ b/projects/auth-with-passport/stubs/rule.stub @@ -0,0 +1,19 @@ +make(Kernel::class)->bootstrap(); + + return $app; + } +} diff --git a/projects/auth-with-passport/tests/Feature/Http/Controllers/V1/.gitkeep b/projects/auth-with-passport/tests/Feature/Http/Controllers/V1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/projects/auth-with-passport/tests/Pest.php b/projects/auth-with-passport/tests/Pest.php new file mode 100644 index 0000000..21f6593 --- /dev/null +++ b/projects/auth-with-passport/tests/Pest.php @@ -0,0 +1,11 @@ +in(__DIR__); diff --git a/projects/auth-with-passport/tests/TestCase.php b/projects/auth-with-passport/tests/TestCase.php new file mode 100644 index 0000000..5341116 --- /dev/null +++ b/projects/auth-with-passport/tests/TestCase.php @@ -0,0 +1,12 @@ +