{"id":21409557,"url":"https://github.com/mahmoudsayed96/login-with","last_synced_at":"2026-02-11T19:32:21.935Z","repository":{"id":124431637,"uuid":"463317419","full_name":"MahmoudSayed96/login-with","owner":"MahmoudSayed96","description":"Laravel steps for make login with provider like Google","archived":false,"fork":false,"pushed_at":"2022-02-24T22:41:51.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-12T12:08:29.022Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MahmoudSayed96.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-24T22:13:10.000Z","updated_at":"2022-02-24T22:13:10.000Z","dependencies_parsed_at":"2023-08-07T17:03:38.702Z","dependency_job_id":null,"html_url":"https://github.com/MahmoudSayed96/login-with","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MahmoudSayed96/login-with","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahmoudSayed96%2Flogin-with","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahmoudSayed96%2Flogin-with/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahmoudSayed96%2Flogin-with/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahmoudSayed96%2Flogin-with/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MahmoudSayed96","download_url":"https://codeload.github.com/MahmoudSayed96/login-with/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahmoudSayed96%2Flogin-with/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269372352,"owners_count":24406271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T17:27:06.259Z","updated_at":"2026-02-11T19:32:16.916Z","avatar_url":"https://github.com/MahmoudSayed96.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Login with Provider [Google, Facebook,...] in Laravel 8\n\nThis repo for explain how Authentication using Google, In this i am going to use Laravel Socialite Package.\n\n[Laravel Socialite](https://github.com/laravel/socialite)\n\n## STEP 1\n\nInstall package with composer.\n```bash\ncomposer require laravel/socialite\n```\nInclude Package in Providers.\nIn `config/app.php` file add the below provider.\n```php\nLaravel\\Socialite\\SocialiteServiceProvider::class,\n```\nScroll Down to aliases section and add below code.\n```php\n'Socialite' =\u003e Laravel\\Socialite\\Facades\\Socialite::class,\n```\n\n## STEP 2\n\u003e Create model `Provider` and table for registeration data of social provider `-m` for migration.\n\n```bash\nphp artisan make:model Provider -m\n```\n\nUpdate providers table\n```php\nSchema::create('providers', function (Blueprint $table) {\n    $table-\u003eid();\n    $table-\u003eunsignedBigInteger('provider_id');\n    $table-\u003estring('provider_name');\n    $table-\u003eunsignedBigInteger('user_id');\n    $table-\u003etimestamps();\n});\n```\nRun this command for migrate table.\n```php\nphp artisan migrate\n```\n\n## STEP 3\nCreate Controller for auth with provider.\n```bash\nphp artisan make:controller AuthSocialiteController\n```\n\n\n## STEP 4\nAdd routes to `web.php`.\n\n```php\n// Auth with provider routes.\nRoute::get('auth/{provider}/redirect', 'AuthSocialiteController@redirectToProvider')-\u003ename('login_with_redirect');\nRoute::get('auth/{provider}/callback', 'AuthSocialiteController@handleProviderCallback')-\u003ename('login_with_callback');\n```\n\n## STEP 5\nAdd functions to controller.\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Models\\Provider;\nuse App\\Models\\User;\nuse Illuminate\\Support\\Facades\\Auth;\nuse Laravel\\Socialite\\Facades\\Socialite;\n\nclass AuthSocialiteController extends Controller\n{\n    public function redirectToProvider($provider)\n    {\n        return Socialite::driver($provider)-\u003eredirect();\n    }\n\n    public function handleProviderCallback($provider)\n    {\n        try {\n            $user = Socialite::driver($provider)-\u003euser();\n            // Check user if already logged with provider.\n            $is_user_exists = Provider::where('user_id', $user-\u003egetId())-\u003efirst();\n            if (!$is_user_exists) {\n                // Check if user already registered by email.\n                $registeredUser = User::where('email', $user-\u003egetEmail())-\u003efirst();\n                if (!$registeredUser) {\n                    // Create new.\n                    $registeredUser = User::updateOrCreate([\n                        'email' =\u003e $user-\u003egetEmail(),\n                        'password' =\u003e bcrypt($user-\u003egetName() . '@' . $user-\u003egetId()),\n                        'phone' =\u003e null,\n                    ]);\n                }\n                // Create provider.\n                Provider::create([\n                    'provider_name' =\u003e $provider,\n                    'provider_id' =\u003e $user-\u003egetId(),\n                    'user_id' =\u003e $registeredUser-\u003eid,\n                ]);\n                Auth::loginUsingId($registeredUser-\u003eid);\n            } else {\n                Auth::loginUsingId($is_user_exists-\u003eid);\n            }\n            return redirect()-\u003eroute('frontend.get_complete_profile');\n        } catch (\\Throwable $th) {\n            throw $th;\n        }\n    }\n}\n```\n\n## STEP 6\nCreate service account on google console for `client_id` and `client_secret`.\nAdd Provider Service in `config/services.php` File.\n```php\n'google' =\u003e [\n    'client_id' =\u003e env('GOOGLE_CLIENT_ID'),\n    'client_secret' =\u003e env('GOOGLE_CLIENT_SECRET'),\n    'redirect' =\u003e env('GOOGLE_REDIRECT_URL'),\n],\n```\n\n### Laravel Socialite: InvalidStateException\nThe Solution\n\nGo to your www root, check the laravel file `config/session.php`\nCheck session Session Cookie Domain The default configuration is `'domain' =\u003e null`,\nI made a change to `'domain' =\u003e 'mysite.com'`.\nAfter `php artisan cache:clear` and `composer dump-autoload`, \nI can login with no issue from both `www.mysite.com` and `mysite.com`\nBe sure to delete your cookies from browser when testing it after \nthese modifications are done. Old cookies can still produce problems.\n```\n[Soluation](https://stackoverflow.com/questions/30660847/laravel-socialite-invalidstateexception)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahmoudsayed96%2Flogin-with","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmahmoudsayed96%2Flogin-with","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahmoudsayed96%2Flogin-with/lists"}