Search code examples
laravellumenlaravel-socialite

Laravel Socialite on Lumen: credentials are not sent along


I'm trying to implement a social login to Linkedin using laravel/socialite on Lumen. Here is the controller for the first login step:

  public function loginLinkedin()
  {
    return Socialite::driver('linkedin')->redirect();
  }

The credentials are stored at the .env configuration file:

LINKEDIN_ID=123whatever
LINKEDIN_SECRET=123whatever
LINKEDIN_URL=http://localhost/linkedin

When I visit my link, the controller redirects me to Linkedin, but I simply get a red badge saying:

The client code is missing. It's necessary to provide a client code in order to continue.

I suspect that laravel/socialite is not able to get my credentials from the .env file. Do I miss something?

It seems to be a generic issue related to Lumen. Usually I see many Laravel packages containing some "config/blabla.php" configuration file, but I don't see how to safely implement such configuration on Lumen.


Solution

  • Thanks to Joseph's answer I came up with a solution - without writing a new manager.

    The whole point was about the ability to read a configuration file on Lumen, since the microframework usually retrieve all config data from the .env file.

    The first step was to edit the original SocialiteManager.php under /vendor/laravel/socialite/src in order to retrieve the Linkedin configuration from the .env file, using the getenv() command. It worked! I reached the Linkedin authentication form and was able to login properly, arriving back at the callback URL.

    So now the problem was to remove the edits on SocialiteManager.php and keep it original. How could I read the /config/services.php file, where the Linkedin configuration was stored?

    The following post came to rescue: https://laracasts.com/discuss/channels/lumen/cant-get-config-data-in-lumen

    It says that it's possible to load regular Laravel configuration files (under /config) following the steps below:

    • on /bootstrap/app.php, uncomment (or add) the line:

      $app->register('App\Providers\AppServiceProvider');

    • on app/Providers/AppServiceProvider.php, fill in the register() function:

      public function register() { $this->app->configure('services'); }

    And now it works!