adamwathan / eloquent-oauth

Braindead simple social login with Laravel and Eloquent.
370 stars 44 forks source link

Unable to register provider later / externally #43

Closed syphernl closed 9 years ago

syphernl commented 9 years ago

We have our own authentication package which is basically a wrapper around this package. This was done in order to make it easier to work with, since only our package (and config) needed to be there and it would supply the underlying eloquent-oauth with appropriate configurations. It also adds some additional routes, views (403 etc) and the related model. All in one package is very convenient.

With Laravel 4(.2) this was working just fine. However, with the dev-laravel-5 version this doesn't work anymore :(

In our serviceprovider we registered our provider as such:

\AdamWathan\EloquentOAuth\Facades\OAuth::registerProvider('CustomAuth', $this->app->make('CustomAuthProvider'));

This was working fine with L4. But with L5 this doesn't appear to be possible (anymore) since we're getting an exception stating:

Invalid argument supplied for foreach() 

This originates from /vagrant/vendor/adamwathan/eloquent-oauth/src/EloquentOAuthServiceProvider.php:

     return $oauth;
    });
    }
    protected function registerProviders($oauth)
    {
    $providerAliases = $this->app['config']['eloquent-oauth.providers'];
    foreach ($providerAliases as $alias => $config) {
    if(isset($this->providerLookup[$alias])) {
    $providerClass = $this->providerLookup[$alias];

Has anything changed in that regard?

adamwathan commented 9 years ago

Hey, I suspect the issue is probably that you have the config file in the wrong place, the location changed from 4 to 5.

Instead of app/config/packages/adamwathan/eloquent-oauth/config.php, the config now just lives in config/eloquent-oauth.php. Lemme know if you already have it set up that way and it's still not working, happy to help figure it out.

syphernl commented 9 years ago

Wow, that was fast :) Tricky thing is that we did not have any separate configuration for this package. It is all being dealt with by our wrapper.

syphernl commented 9 years ago

A (somewhat) nasty workaround is to create the provider manually, instead of going trough registerProvider in boot() of our package:

$this->app['config']['eloquent-oauth.providers.customauth'] = $this->app['config']['customauth.providers.customauth'];
adamwathan commented 9 years ago

Hm so where do you keep your client_ids and client_secrets? There must be some config file? It sounds like you just won't be able to use the service provider and will have to configure the package dependencies in your own service provider.

syphernl commented 9 years ago

We store our client_id, client_secret and additional information in our own configuration.

adamwathan commented 9 years ago

Ok, so definitely need your own service provider. I suspect you had your own service provider for the L4 version too, or you would've had the same issues I think.

I'd say try just completely copying the service provider and renaming it to CustomAuthServiceProvider and sticking it in your Providers namespace, and just modify any references to the default config and replace it with yours.

syphernl commented 9 years ago

Hmm, that does mean that we might run into problems in case the original provider for this package has changes. Previously they would play nice together. We register our provider, which then registers this package's provider.

For now the config setting in boot() seems to work, but previously there was no problem with it when there were no providers configured at all which is a bit odd.

adamwathan commented 9 years ago

Did you still have the app/config/packages/adamwathan/eloquent-oauth/config.php file, just as an empty array maybe? That would probably also solve your issue.

I'm gonna look at updating the service provider to skip provider registration if there's no config file, :+1:

adamwathan commented 9 years ago

Pushed out a change that I expect will fix your issue, lemme know if it does :)

syphernl commented 9 years ago

Appears to be working without me having to set the config via $this->app['config']['eloquent-oauth.providers.sentry'] :)