Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to register provider later / externally #43

Closed
syphernl opened this issue Mar 13, 2015 · 10 comments
Closed

Unable to register provider later / externally #43

syphernl opened this issue Mar 13, 2015 · 10 comments

Comments

@syphernl
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor Author

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

@adamwathan
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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, 👍

@adamwathan
Copy link
Owner

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

@syphernl
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants