]> _ Git - cubist_socialite.git/commitdiff
wip #4765 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Oct 2021 18:30:24 +0000 (20:30 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Oct 2021 18:30:24 +0000 (20:30 +0200)
composer.json
src/CubistSocialiteAuthProvider.php [new file with mode: 0644]

index bf7de39613398ee92cb5de5420dbecefd639ab72..06061f91997242431ee864e47424996b48f898fa 100644 (file)
@@ -36,7 +36,8 @@
   "extra": {
     "laravel": {
       "providers": [
-        "Cubist\\Socialite\\CubistSocialiteServiceProvider"
+        "Cubist\\Socialite\\CubistSocialiteServiceProvider",
+        "Cubist\\Socialite\\CubistSocialiteAuthServiceProvider",
       ]
     }
   }
diff --git a/src/CubistSocialiteAuthProvider.php b/src/CubistSocialiteAuthProvider.php
new file mode 100644 (file)
index 0000000..56d51cf
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace Cubist\Socialite;
+
+use Illuminate\Foundation\Support\Providers\AuthServiceProvider;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Laravel\Socialite\Facades\Socialite;
+
+class CubistSocialiteAuthProvider extends AuthServiceProvider
+{
+    /**
+     * Register any application authentication / authorization services.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        $this->registerPolicies();
+
+        Auth::viaRequest('socialitegoogle', function (Request $request) {
+            $socialiteUser = Socialite::driver('google')->user();
+            if ($socialiteUser) {
+                $userClass = config('auth.providers.users.model');
+                $instance = new $userClass();
+                $instance->id = $socialiteUser->getId();
+                $instance->email = $socialiteUser->getEmail();
+            }
+        });
+    }
+}
\ No newline at end of file