-1

Or how can i dynamically set the redirect uri? I'm constantly having to solve merge conflicts because my local and production server use different redirects. Or maybe I should add services.php to gitignore?

my service.php

'google' =>[
    'client_id'=> env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'redirect' =>'http://localhost:3000/login/google/callback', 
],

I want to include a uri for production like

http://example.com/login/google/callback

I've tried using an array which didn't work

jackjoesmith
  • 951
  • 4
  • 20
  • 33
  • Have you tried using `'redirect' => url('login/google/callback'),`? This would set the URI correctly depending on whether you were running on production or locally. – James Sep 25 '15 at 03:52

3 Answers3

2

You can set relative path instead of url() function. Socialite automatically add full url while requesting. Check below note

https://laravel.com/docs/8.x/socialite If the redirect option contains a relative path, it will automatically be resolved to a fully qualified URL.

1

You could set this dynamically with url(). This way it would update appropriately on any environment.

In your case it would look like this:

'google' =>[
    'client_id'=> env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'redirect' => url('login/google/callback'), 
],
James
  • 15,754
  • 12
  • 73
  • 91
1

You shouldn't use url() in config files. It conflicts with PHP artisan. Just need to add all your callback URL to Google Developers Console

http://localhost:3000/login/google/callback
http://example.com/login/google/callback
Giangimgs
  • 952
  • 1
  • 12
  • 16