]> _ Git - cubist_socialite.git/commitdiff
wip #4765 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Oct 2021 17:20:56 +0000 (19:20 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Oct 2021 17:20:56 +0000 (19:20 +0200)
.idea/cubist_socialite.iml
composer.json
composer.lock
src/Http/Controllers/SocialiteController.php
src/User.php [new file with mode: 0644]

index 846927c95ce76961a695347eaa2b3ac93f56bbd3..380d96fc3fad06c463ead80278929e3b17b1ee4d 100644 (file)
@@ -74,6 +74,7 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/psr/event-dispatcher" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-client" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/spatie/laravel-permission" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
index 8001da212bf95f4ee7f927189ae3e5e33afdad97..1bddf5e174b94c5abd876a9724a607bf404f8e26 100644 (file)
@@ -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": [
     {
index 7ddb0b87aa5b3793b28af75a8463d480200d0602..2152b3b7255bc5c92be72dc153c6bb7282052981 100644 (file)
@@ -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",
             },
             "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",
index 3554a92342fe02c7f8172f8ff1473d8435550d4a..420ba6574f3d35e88bab5cd0c84f7fa9b0e65b98 100644 (file)
@@ -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 (file)
index 0000000..ae1aa74
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+namespace Cubist\Socialite;
+
+use Illuminate\Auth\Authenticatable;
+use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
+use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
+use Illuminate\Foundation\Auth\Access\Authorizable;
+use Illuminate\Notifications\Notifiable;
+use Spatie\Permission\Traits\HasRoles;
+
+class User implements
+    AuthenticatableContract,
+    AuthorizableContract
+{
+    use Authenticatable, Authorizable;
+    use Notifiable;
+    use HasRoles;
+
+    protected $provider;
+
+    protected $name;
+    protected $email;
+    protected $avatar;
+    protected $id;
+    protected $nickname;
+
+    /**
+     * @var \Laravel\Socialite\Contracts\User
+     */
+    protected $socialiteUser;
+
+    public function __construct($socialiteUser)
+    {
+        $this->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