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

Can't authenticate with client_credentials grant #68

Open
aukraiser opened this issue Jan 15, 2019 · 8 comments
Open

Can't authenticate with client_credentials grant #68

aukraiser opened this issue Jan 15, 2019 · 8 comments

Comments

@aukraiser
Copy link

aukraiser commented Jan 15, 2019

First of all thanks for this awesome package !
I seem to have an issue with client_credentials grant that look like this one #33.

When I try to authenticate a client using client_credentials I get an error from the AddCustomProvider rejecting my request because I did not specify a provider.

My request contains the requested parameters for a client_credentials:

grant_type: client_credentials
client_id: 1
client_secret: Vx0HRmHsc7jjc8teYdasrx10ajPUWDH4B90Elznd

The AddCustomProvider answers

The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed

If I specify a provider I can authenticate (but I shouldn't have to because I am not trying to authenticate a user).
If I unwrap the Passport::routes in the AuthServiceProvider I can authenticate my client without passing a provider but then the user authentication does not work anymore.

Could it be possible to check for the provider param only in the context of an user authentication ?

@sfelix-martins
Copy link
Owner

@aukraiser Thanks for your issue. Did you solve the problem already?

It's really a problem. The middleware AddCustomProvider checks if the param provider exists on request. But to grant_type client_credentials it shouldn't happens.

    public function handle(Request $request, Closure $next)
    {
        $this->defaultApiProvider = config('auth.guards.api.provider');

        $provider = $request->get('provider');

        if ($this->invalidProvider($provider)) { // HERE 
            throw OAuthServerException::invalidRequest('provider');
        }

        config(['auth.guards.api.provider' => $provider]);

        return $next($request);
    }

I think that if we check if the grant type is client_credentials before check the provider param the problem can be solved. What's you think about it?

Can you create Pull Request, please?

@gierappa
Copy link

gierappa commented Aug 8, 2019

@sfelix-martins How about setting a provider in oauth_access_token_providers to be nullable? It works for me.

Of course AddCustomProvider.php must be modified to ignore client_credentials grant_type request.

@aukraiser
Copy link
Author

@sfelix-martins I'm so sorry for the delayed response. Basically what I did was adding the CheckClientCredentials middleware before the MultiAuthenticate in the route middleware array. But I don't think it should be done this way (though it's working pretty well).

The solution you propose is quite a good one. Did you implement it or do you still need someone to make a pull request?

@sfelix-martins
Copy link
Owner

@aukraiser can you create pull request? It would help me a lot! Thanks!

@aukraiser
Copy link
Author

@sfelix-martins Ok, I'll try to do that today or tomorrow 👍

@aukraiser
Copy link
Author

aukraiser commented Aug 29, 2019

@sfelix-martins, the pull request is created and can be seen here. Hope it'll help 😃

@sfelix-martins
Copy link
Owner

@aukraiser thanks bro. I will check to accept ASAP.

@huynhphan89
Copy link

@sfelix-martins I face this issue now. Could you please check the pull request? Thanks.

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

4 participants