From 6ac422b7b28c298231b91092d43d7d9ce95aea76 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 7 Oct 2021 19:20:56 +0200 Subject: [PATCH] wip #4765 @1 --- .idea/cubist_socialite.iml | 1 + composer.json | 3 +- composer.lock | 84 +++++++++++++++++++- src/Http/Controllers/SocialiteController.php | 9 ++- src/User.php | 78 ++++++++++++++++++ 5 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 src/User.php diff --git a/.idea/cubist_socialite.iml b/.idea/cubist_socialite.iml index 846927c..380d96f 100644 --- a/.idea/cubist_socialite.iml +++ b/.idea/cubist_socialite.iml @@ -74,6 +74,7 @@ + diff --git a/composer.json b/composer.json index 8001da2..1bddf5e 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "php": ">=7.3.0", "laravel/framework": "~5.8|^6.0|^7.0|^8.0", "laravel/socialite": "^v5.2.5", - "socialiteproviders/google": "^4.1.0" + "socialiteproviders/google": "^4.1.0", + "spatie/laravel-permission": "^5.1" }, "repositories": [ { diff --git a/composer.lock b/composer.lock index 7ddb0b8..2152b3b 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": "916d7e90dfa6ee9e0626bd40cfe06971", + "content-hash": "8b8015300b432692677e4ad1b680c0e0", "packages": [ { "name": "brick/math", @@ -2688,6 +2688,88 @@ }, "time": "2020-12-01T23:09:06+00:00" }, + { + "name": "spatie/laravel-permission", + "version": "5.1.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-permission.git", + "reference": "58d5eb6c7b0eafa8bdf0a93d1ca5c214a05344cb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/58d5eb6c7b0eafa8bdf0a93d1ca5c214a05344cb", + "reference": "58d5eb6c7b0eafa8bdf0a93d1ca5c214a05344cb", + "shasum": "" + }, + "require": { + "illuminate/auth": "^6.0|^7.0|^8.0", + "illuminate/container": "^6.0|^7.0|^8.0", + "illuminate/contracts": "^6.0|^7.0|^8.0", + "illuminate/database": "^6.0|^7.0|^8.0", + "php": "^7.2.5|^8.0" + }, + "require-dev": { + "orchestra/testbench": "^4.0|^5.0|^6.0", + "phpunit/phpunit": "^8.0|^9.0", + "predis/predis": "^1.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Permission\\PermissionServiceProvider" + ] + }, + "branch-alias": { + "dev-main": "5.x-dev", + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Spatie\\Permission\\": "src" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Permission handling for Laravel 6.0 and up", + "homepage": "https://github.com/spatie/laravel-permission", + "keywords": [ + "acl", + "laravel", + "permission", + "permissions", + "rbac", + "roles", + "security", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-permission/issues", + "source": "https://github.com/spatie/laravel-permission/tree/5.1.1" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2021-09-01T20:02:17+00:00" + }, { "name": "swiftmailer/swiftmailer", "version": "v6.2.7", diff --git a/src/Http/Controllers/SocialiteController.php b/src/Http/Controllers/SocialiteController.php index 3554a92..420ba65 100644 --- a/src/Http/Controllers/SocialiteController.php +++ b/src/Http/Controllers/SocialiteController.php @@ -3,7 +3,9 @@ namespace Cubist\Socialite\Http\Controllers; use Cubist\Socialite\CubistSocialiteServiceProvider; +use Cubist\Socialite\User; use Illuminate\Routing\Controller; +use Illuminate\Support\Facades\Auth; use Laravel\Socialite\Facades\Socialite; class SocialiteController extends Controller @@ -29,9 +31,10 @@ class SocialiteController extends Controller { $provider = request()->provider; if (in_array($provider, $this->providers)) { - $data = Socialite::driver($provider)->user(); - $user = $data->user; - dd($user); + $socialiteUser=Socialite::driver($provider)->user(); + if($socialiteUser) { + Auth::login(new User($socialiteUser),true); + } } abort(403); } diff --git a/src/User.php b/src/User.php new file mode 100644 index 0000000..ae1aa74 --- /dev/null +++ b/src/User.php @@ -0,0 +1,78 @@ +socialiteUser=$socialiteUser; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->socialiteUser->getName(); + } + + /** + * @return mixed + */ + public function getAvatar() + { + return $this->socialiteUser->getAvatar(); + } + + /** + * @return mixed + */ + public function getEmail() + { + return $this->socialiteUser->getEmail(); + } + + /** + * @return mixed + */ + public function getNickname() + { + return $this->socialiteUser->getNickname(); + } + + /** + * @return mixed + */ + public function getId() + { + return $this->socialiteUser->getId(); + } + +} \ No newline at end of file -- 2.39.5