From 511e857cb80363de66e38d92303071ed32619223 Mon Sep 17 00:00:00 2001 From: stevan06v Date: Tue, 19 Mar 2024 18:31:55 +0100 Subject: [PATCH] feat: added auth via oath app closes #134 --- .env.dev.example | 4 + .env.docker.example | 4 + .env.example | 4 + app/Http/Controllers/GithubController.php | 44 ++ app/Models/User.php | 2 + composer.json | 5 +- composer.lock | 464 +++++++++++++++++- config/services.php | 5 + .../2014_10_12_000000_create_users_table.php | 3 + resources/views/livewire/auth/login.blade.php | 9 +- .../views/livewire/auth/register.blade.php | 1 + .../views/livewire/monitors/card.blade.php | 3 +- .../livewire/monitors/read-me-view.blade.php | 16 + .../views/livewire/monitors/show.blade.php | 2 + routes/web.php | 7 +- 15 files changed, 567 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/GithubController.php create mode 100644 resources/views/livewire/monitors/read-me-view.blade.php diff --git a/.env.dev.example b/.env.dev.example index 80cc86f..2bb8e1d 100644 --- a/.env.dev.example +++ b/.env.dev.example @@ -16,6 +16,10 @@ DB_DATABASE=propromo DB_USERNAME=postgres DB_PASSWORD=propromo +GITHUB_CLIENT_ID=b6e2c09ada28dae5186e +GITHUB_CLIENT_SECRET=ff191c19a886b5e159e7882d0511d6e217f37d9a +GITHUB_CALLBACK_URI=http://propromo.test/auth/github/callback + BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local diff --git a/.env.docker.example b/.env.docker.example index 8beda78..135e592 100644 --- a/.env.docker.example +++ b/.env.docker.example @@ -16,6 +16,10 @@ DB_DATABASE=propromo DB_USERNAME=postgres DB_PASSWORD=propromo +GITHUB_CLIENT_ID=b6e2c09ada28dae5186e +GITHUB_CLIENT_SECRET=ff191c19a886b5e159e7882d0511d6e217f37d9a +GITHUB_CALLBACK_URI=http://propromo.test/auth/github/callback + BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local diff --git a/.env.example b/.env.example index 8beda78..135e592 100644 --- a/.env.example +++ b/.env.example @@ -16,6 +16,10 @@ DB_DATABASE=propromo DB_USERNAME=postgres DB_PASSWORD=propromo +GITHUB_CLIENT_ID=b6e2c09ada28dae5186e +GITHUB_CLIENT_SECRET=ff191c19a886b5e159e7882d0511d6e217f37d9a +GITHUB_CALLBACK_URI=http://propromo.test/auth/github/callback + BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local diff --git a/app/Http/Controllers/GithubController.php b/app/Http/Controllers/GithubController.php new file mode 100644 index 0000000..cd1c2de --- /dev/null +++ b/app/Http/Controllers/GithubController.php @@ -0,0 +1,44 @@ +redirect(); + } + + /** + * @throws Exception + */ + public function callback() + { + try { + $user = Socialite::driver('github')->user(); + + $git_user = User::updateOrCreate([ + 'github_id' => $user->id + ], [ + 'name' => $user->name, + 'nickname' => $user->nickname, + 'email' => $user->email, + 'github_token' => $user->token, + 'auth_type' => 'GITHUB', + 'password' => Hash::make(Str::random(10)) + ]); + Auth::login($git_user); + + return redirect(route('home.index')); + } catch (Exception $e) { + throw new Exception("Error occured while trying to authorize via github...".$e->getMessage()); + } + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 7718d5e..e719717 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -56,6 +56,8 @@ class User extends Authenticatable protected $fillable = [ 'name', 'email', + 'github_id', + 'auth_type', 'password', ]; diff --git a/composer.json b/composer.json index d173c13..a19cdbb 100644 --- a/composer.json +++ b/composer.json @@ -9,10 +9,13 @@ "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^10.10", "laravel/sanctum": "^3.3", + "laravel/socialite": "^5.12", "laravel/tinker": "^2.8", "livewire/livewire": "^3.4", "livewire/volt": "^1.6", - "robsontenorio/mary": "^1.25" + "robsontenorio/mary": "^1.25", + "spatie/laravel-markdown": "^2.5", + "ueberdosis/pandoc": "^0.9.0" }, "require-dev": { "barryvdh/laravel-ide-helper": "^3.0", diff --git a/composer.lock b/composer.lock index 1308d29..0a23477 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0a70fce20747ec324b85d0f1bda20a48", + "content-hash": "42bce6178ac4f64abfcf2902ed34b412", "packages": [ { "name": "blade-ui-kit/blade-heroicons", @@ -1822,6 +1822,76 @@ }, "time": "2023-11-08T14:08:06+00:00" }, + { + "name": "laravel/socialite", + "version": "v5.12.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/socialite.git", + "reference": "7dae1b072573809f32ab6dcf4aebb57c8b3e8acf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/socialite/zipball/7dae1b072573809f32ab6dcf4aebb57c8b3e8acf", + "reference": "7dae1b072573809f32ab6dcf4aebb57c8b3e8acf", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/guzzle": "^6.0|^7.0", + "illuminate/contracts": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/http": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "league/oauth1-client": "^1.10.1", + "php": "^7.2|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0|^9.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8.0|^9.3|^10.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Socialite\\SocialiteServiceProvider" + ], + "aliases": { + "Socialite": "Laravel\\Socialite\\Facades\\Socialite" + } + } + }, + "autoload": { + "psr-4": { + "Laravel\\Socialite\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel wrapper around OAuth 1 & OAuth 2 libraries.", + "homepage": "https://laravel.com", + "keywords": [ + "laravel", + "oauth" + ], + "support": { + "issues": "https://github.com/laravel/socialite/issues", + "source": "https://github.com/laravel/socialite" + }, + "time": "2024-02-16T08:58:20+00:00" + }, { "name": "laravel/tinker", "version": "v2.9.0", @@ -2282,6 +2352,82 @@ ], "time": "2024-01-28T23:22:08+00:00" }, + { + "name": "league/oauth1-client", + "version": "v1.10.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/oauth1-client.git", + "reference": "d6365b901b5c287dd41f143033315e2f777e1167" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/oauth1-client/zipball/d6365b901b5c287dd41f143033315e2f777e1167", + "reference": "d6365b901b5c287dd41f143033315e2f777e1167", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-openssl": "*", + "guzzlehttp/guzzle": "^6.0|^7.0", + "guzzlehttp/psr7": "^1.7|^2.0", + "php": ">=7.1||>=8.0" + }, + "require-dev": { + "ext-simplexml": "*", + "friendsofphp/php-cs-fixer": "^2.17", + "mockery/mockery": "^1.3.3", + "phpstan/phpstan": "^0.12.42", + "phpunit/phpunit": "^7.5||9.5" + }, + "suggest": { + "ext-simplexml": "For decoding XML-based responses." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev", + "dev-develop": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\OAuth1\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Corlett", + "email": "bencorlett@me.com", + "homepage": "http://www.webcomm.com.au", + "role": "Developer" + } + ], + "description": "OAuth 1.0 Client Library", + "keywords": [ + "Authentication", + "SSO", + "authorization", + "bitbucket", + "identity", + "idp", + "oauth", + "oauth1", + "single sign on", + "trello", + "tumblr", + "twitter" + ], + "support": { + "issues": "https://github.com/thephpleague/oauth1-client/issues", + "source": "https://github.com/thephpleague/oauth1-client/tree/v1.10.1" + }, + "time": "2022-04-15T14:02:14+00:00" + }, { "name": "livewire/livewire", "version": "v3.4.9", @@ -3807,6 +3953,266 @@ ], "time": "2024-03-07T17:01:55+00:00" }, + { + "name": "spatie/commonmark-shiki-highlighter", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/commonmark-shiki-highlighter.git", + "reference": "7d7c4f5f1b387bc3144f7757a85eef6820776929" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/commonmark-shiki-highlighter/zipball/7d7c4f5f1b387bc3144f7757a85eef6820776929", + "reference": "7d7c4f5f1b387bc3144f7757a85eef6820776929", + "shasum": "" + }, + "require": { + "league/commonmark": "^2.4.2", + "php": "^8.0", + "spatie/shiki-php": "^2.0", + "symfony/process": "^6.0|^7.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.19|^v3.49.0", + "phpunit/phpunit": "^9.5", + "spatie/phpunit-snapshot-assertions": "^4.2.7", + "spatie/ray": "^1.28" + }, + "type": "commonmark-extension", + "autoload": { + "psr-4": { + "Spatie\\CommonMarkShikiHighlighter\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Highlight code blocks with league/commonmark and Shiki", + "homepage": "https://github.com/spatie/commonmark-shiki-highlighter", + "keywords": [ + "commonmark-shiki-highlighter", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/commonmark-shiki-highlighter/tree/2.3.0" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-02-19T09:14:06+00:00" + }, + { + "name": "spatie/laravel-markdown", + "version": "2.5.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-markdown.git", + "reference": "76b0d5fe809c61bb4c2208df3f1115a5db0ceb3b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-markdown/zipball/76b0d5fe809c61bb4c2208df3f1115a5db0ceb3b", + "reference": "76b0d5fe809c61bb4c2208df3f1115a5db0ceb3b", + "shasum": "" + }, + "require": { + "illuminate/cache": "^9.0|^10.0|^11.0", + "illuminate/contracts": "^9.0|^10.0|^11.0", + "illuminate/support": "^9.0|^10.0|^11.0", + "illuminate/view": "^9.0|^10.0|^11.0", + "league/commonmark": "^2.4.2", + "php": "^8.1", + "spatie/commonmark-shiki-highlighter": "^2.3", + "spatie/laravel-package-tools": "^1.4.3" + }, + "require-dev": { + "brianium/paratest": "^6.2", + "nunomaduro/collision": "^5.3|^6.0", + "orchestra/testbench": "^6.15|^7.0|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.3", + "spatie/laravel-ray": "^1.23", + "spatie/pest-plugin-snapshots": "^1.1", + "vimeo/psalm": "^4.8" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\LaravelMarkdown\\MarkdownServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\LaravelMarkdown\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "A highly configurable markdown renderer and Blade component for Laravel", + "homepage": "https://github.com/spatie/laravel-markdown", + "keywords": [ + "Laravel-Markdown", + "laravel", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-markdown/tree/2.5.0" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-02-26T14:24:08+00:00" + }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.3", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "59db18c2e20d49a0b6d447bb1c654f6c123beb9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/59db18c2e20d49a0b6d447bb1c654f6c123beb9e", + "reference": "59db18c2e20d49a0b6d447bb1c654f6c123beb9e", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0|^11.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.3" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-03-07T07:35:57+00:00" + }, + { + "name": "spatie/shiki-php", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/shiki-php.git", + "reference": "b4bd54222c40b44800aabce0a4382e0c463b5901" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/shiki-php/zipball/b4bd54222c40b44800aabce0a4382e0c463b5901", + "reference": "b4bd54222c40b44800aabce0a4382e0c463b5901", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.4|^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^v3.0", + "pestphp/pest": "^1.8", + "phpunit/phpunit": "^9.5", + "spatie/pest-plugin-snapshots": "^1.1", + "spatie/ray": "^1.10" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\ShikiPhp\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Rias Van der Veken", + "email": "rias@spatie.be", + "role": "Developer" + }, + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Highlight code using Shiki in PHP", + "homepage": "https://github.com/spatie/shiki-php", + "keywords": [ + "shiki", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/shiki-php/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-02-19T09:00:59+00:00" + }, { "name": "symfony/console", "version": "v6.4.4", @@ -6090,6 +6496,62 @@ }, "time": "2023-12-08T13:03:43+00:00" }, + { + "name": "ueberdosis/pandoc", + "version": "0.9.0", + "source": { + "type": "git", + "url": "https://github.com/ueberdosis/pandoc.git", + "reference": "c5f16d52170e0622d6d3ef8350e08d0799809049" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ueberdosis/pandoc/zipball/c5f16d52170e0622d6d3ef8350e08d0799809049", + "reference": "c5f16d52170e0622d6d3ef8350e08d0799809049", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0", + "symfony/process": ">4.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.0 || ^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Pandoc\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Hans Pagel", + "email": "hans.pagel@ueber.io", + "role": "Developer" + } + ], + "description": "Pandoc PHP Package", + "homepage": "https://github.com/ueberdosis/pandoc", + "keywords": [ + "pandoc", + "ueberdosis" + ], + "support": { + "issues": "https://github.com/ueberdosis/pandoc/issues", + "source": "https://github.com/ueberdosis/pandoc/tree/0.9.0" + }, + "funding": [ + { + "url": "https://github.com/sponsors/ueberdosis/", + "type": "github" + } + ], + "time": "2023-02-28T08:00:44+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v5.6.0", diff --git a/config/services.php b/config/services.php index 0ace530..8490715 100644 --- a/config/services.php +++ b/config/services.php @@ -30,5 +30,10 @@ 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), ], + 'github' => [ + 'client_id' => env('GITHUB_CLIENT_ID'), + 'client_secret' => env('GITHUB_CLIENT_SECRET'), + 'redirect' => env('GITHUB_CALLBACK_URI'), + ] ]; 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 814b11a..e9a3340 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -13,9 +13,12 @@ public function up(): void Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->string('nickname')->nullable(); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); + $table->string('github_id')->nullable(); + $table->string('auth_type'); $table->rememberToken(); $table->timestamps(); }); diff --git a/resources/views/livewire/auth/login.blade.php b/resources/views/livewire/auth/login.blade.php index 5578098..4cf4e51 100644 --- a/resources/views/livewire/auth/login.blade.php +++ b/resources/views/livewire/auth/login.blade.php @@ -55,17 +55,22 @@ class="w-full sm:max-w-md mt-6 p-12 bg-white dark:bg-gray-800 border-[1px] borde
-
+
+ + + +
+
+ @if($account_login_message) diff --git a/resources/views/livewire/auth/register.blade.php b/resources/views/livewire/auth/register.blade.php index f99bae7..d5473cd 100644 --- a/resources/views/livewire/auth/register.blade.php +++ b/resources/views/livewire/auth/register.blade.php @@ -30,6 +30,7 @@ public function save() $user = User::create([ "name" => $this->name, "email" => $this->email, + "auth_type"=> "PROPROMO", "password" => $this->password ]); diff --git a/resources/views/livewire/monitors/card.blade.php b/resources/views/livewire/monitors/card.blade.php index 42d371d..ab5825e 100644 --- a/resources/views/livewire/monitors/card.blade.php +++ b/resources/views/livewire/monitors/card.blade.php @@ -69,12 +69,13 @@ public function get_repositories() - + @if($collect_repos_error) diff --git a/resources/views/livewire/monitors/read-me-view.blade.php b/resources/views/livewire/monitors/read-me-view.blade.php new file mode 100644 index 0000000..6f53f90 --- /dev/null +++ b/resources/views/livewire/monitors/read-me-view.blade.php @@ -0,0 +1,16 @@ + +
+ {{ $markdown_content }} +
diff --git a/resources/views/livewire/monitors/show.blade.php b/resources/views/livewire/monitors/show.blade.php index d58139c..0594920 100644 --- a/resources/views/livewire/monitors/show.blade.php +++ b/resources/views/livewire/monitors/show.blade.php @@ -18,4 +18,6 @@ public function mount(Monitor $monitor)
+ + diff --git a/routes/web.php b/routes/web.php index 73beac4..8e1f7fd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,11 +1,12 @@ name('home.index'); Volt::route('/login', 'auth.login'); @@ -14,6 +15,10 @@ return Redirect::to('login'); }); +Route::get('/auth/github', [GithubController::class,'redirect'])->name('github.login'); +Route::get('/auth/github/callback', [GithubController::class,'callback']); + + Volt::route('/monitors', 'monitors.index'); Volt::route('/monitors/{monitor}', 'monitors.show');