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

Proxy.php line 46 - First parameter must either be an object or the name of an existing class #15

Open
sachinvrg opened this issue Sep 28, 2015 · 20 comments

Comments

@sachinvrg
Copy link

Hello All,

Can anybody please help me to sort out this issue, I have tried everything, even downloaded the zip and extract it, but the setup is not working, Is this setup has any bug? could anyone be able to run this setup?
I am getting the same error as almost everyone has -
Proxy.php line 46 - First parameter must either be an object or the name of an existing class

Thank You.

@prashantidealittechno
Copy link

I have the same issue, please help.

@prashantidealittechno
Copy link

Okay I have resolved the above error by adding port number to my url in config/app.php , e.g. http://192.0.0.0:8000
then in .env file I changed SESSION_DRIVER=cookie
but now when I click on login button and checked in console, it is just loading, nothing happens.
and when I hit http://192.0.0.0:8000/oauth/access-token with
username, password, client_id, client_secret and grant_type through postman then it is giving response as -
Array
(
[access_token] => 6TxUnhoXF659fku3t6D2CRM3XewOmXup6xbAUBBz
[token_type] => Bearer
[expires_in] => 10
[refresh_token] => BLQqBTaTn8s6jq9yjepRGFWOGvP882LqzMEYf4Sa
)

can you please help?

@rahul9874563210
Copy link

i have same issue.
After changing SESSION_DRIVER memcached to cookie still i'm getting the same error
ErrorException in Proxy.php line 46: First parameter must either be an object or the name of an existing class.
Since i didn't added the port number in my url i just did with my VH name i.e. (lumenoauth.dev).
someone please help.

@prashantidealittechno
Copy link

did you try to debug it with adding -

print_r($data);
echo sprintf('%s/oauth/access-token', $config->get('app.url'));
die;

these lines just above $client = new Client(); this lines, then try that url and parameters with postman or poster or any other rest client ?

@rahul9874563210
Copy link

i used

            use Illuminate\Support\Facades\URL;

            print_r($data);

            echo sprintf('%s/oauth/access-token', URL::current());

            die;

it alerts a message saying something went wrong.
and return

Array
(
    [username] => rahul.prajapati@ambab.com
    [password] => 1234
)
http://lumenoauth.dev/login/oauth/access-token

@prashantidealittechno
Copy link

@rahul9874563210
I think you are missing something , you must have client_id, client_secret and grant_type in your $data array, make sure you migrated all the oauth tables properly.

@esbenp
Copy link
Owner

esbenp commented Oct 17, 2015

You will most likely get this error because the Guzzle request was not completed successfully. This happened to me because I did not change the app url in config/app.php https://github.com/esbenp/lumen-api-oauth/blob/master/config/app.php to the correct url.

@nomoregrapes
Copy link

I'm stuck on not getting a response too.

First parameter must either be an object or the name of an existing class

Outputting before the $client = new Client(); I get...

Array ( [client_id] => 1 [client_secret] => gKYG75sw [grant_type] => password [username] => user@user.com [password] => 1234 )
http://profile.testwebsite.local/oauth/access-token

When I use that URL and the parameters in Postman (or even "Advanced Rest Client Application") I oddly get an error The request is missing a required parameter,.... Check the "grant_type" parameter..
I don't get that error with my test client, unless I change the code to remove the grant_type.

The URL I have in config/app.php is http://profile.testwebsite.local

@tr33m4n
Copy link

tr33m4n commented Nov 30, 2015

I'm having a similar issue, I'm passing client_id, client_secret, grant_type, username and password to /oauth/access-token with paw/postman/whichever and receiving back the error

Fatal error: Class '\App\User' not found in /vendor/illuminate/auth/EloquentUserProvider.php on line 126

Which is a little odd, so it appears to be failing when retrieving the user after receiving a token... Any ideas?

Cheers

@tr33m4n
Copy link

tr33m4n commented Nov 30, 2015

Well, rookie mistake here... Moving the User.php to the App route fixed it. Will update where the model resides later... For what it's worth, I'm using Dingo and my routes look like this

$api->version('v1', ['middleware' => 'api.throttle', 'throttle' => 'App\Throttle\GroupThrottle', 'middleware' => 'cors'], function ($api) {
    $api->get('/', function() use ($api) {
        return view()->make('client');
    });
    $api->post('login', 'App\\Auth\\Proxy@attemptLogin');
    $api->post('refresh-token', 'App\\Auth\\Proxy@attemptRefresh');
    $api->post('oauth/access-token', 'LucaDegasperi\\OAuth2Server\\Authorizer@issueAccessToken');
    $api->group(['middleware' => 'oauth'], function($api) {
        $api->get('resource', function() {
            return response()->json([
                'id' => 1,
                'name' => 'A resource'
            ]);
        });
    });
});

I've also removed the optimus oauth2 lumen package and replaced it with "lucadegasperi/oauth2-server-laravel": "^5.0" as it now supports Lumen 5 officially (you'll have to change the middleware and register params as per the config).

I also had to update the oauth2 config file like so:

'grant_types' => [
        'password' => [
            'class' => '\League\OAuth2\Server\Grant\PasswordGrant',
            'callback' => '\App\Grant\PasswordGrantVerifier@verify',
            'access_token_ttl' => 3600
        ],
        'refresh_token' => [
            'class' => '\League\OAuth2\Server\Grant\RefreshTokenGrant',
            'access_token_ttl' => 3600,
            'refresh_token_ttl' => 36000
        ]
    ],

And created a verify function in the PasswordGrantVerifier class:

namespace App\Grant;

use Illuminate\Support\Facades\Auth;

class PasswordGrantVerifier
{
    public function verify($username, $password) {
        $credentials = [
        'email'    => $username,
        'password' => $password,
        ];

        if (Auth::once($credentials)) {
            return Auth::user()->id;
        }

        return false;
    }
}

Hope this helps someone!
Cheers

@tr33m4n
Copy link

tr33m4n commented Nov 30, 2015

But still getting the First parameter must either be an object or the name of an existing class issue, will update when I know more

@tr33m4n
Copy link

tr33m4n commented Nov 30, 2015

At least PAW/Postman works now

@tr33m4n
Copy link

tr33m4n commented Nov 30, 2015

Also, I modified Proxy.php like so (to use the request object):

namespace App\Auth;

use GuzzleHttp\Client;
use Illuminate\Http\Request;

class Proxy {

    public function attemptLogin(Request $request) {
        $credentials = $request->get('credentials');
        return $this->proxy('password', $credentials);
    }

@tr33m4n
Copy link

tr33m4n commented Nov 30, 2015

Well, it appears I just needed to alter the url for my access-token (as they're being prefixed with api)... Works like a charm now

@Pitu
Copy link

Pitu commented Dec 9, 2015

@tr33m4n hey man, I'm having the same issue as you did before. When using postman my error is

{
  "error": "invalid_request",
  "error_description": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"grant_type\" parameter."
}

I tried following everyone's suggestions but I can't seem to make it work. Would it be possible for you to share your lumen folder with the changes you made, to see if I can get this to work? I've been bashing my head against the wall for the past 3 days.

Thanks!

@sachinvrg
Copy link
Author

okay everyone, I have already made this working, may be I can help you. @pituseligmann can you please let me know what request you are submitting with postman?
I think you are missing parameter access_token

@Pitu
Copy link

Pitu commented Dec 10, 2015

Hi @sachinvrg , this is the request I'm trying to submit via postman without success:
http://i.imgur.com/coC54r0.png

As far as I know, I shouldn't need to pass a access_token parameter at this point.

@atlcell
Copy link

atlcell commented Aug 3, 2016

@pituseligmann Pitu, did you have any luck fixing your problem at this point?

@Pitu
Copy link

Pitu commented Aug 4, 2016

Sadly i moved away from Lumen and went right into Laravel since it was so much easier to set up.

@ghost
Copy link

ghost commented Aug 30, 2016

I had the same Problem. I solved it because my route was defined with "access_token" and not "access-token". I changed the route at the Proxy.php to ... $config->get('app.url')."/oauth/access_token" ... Maybe someone has the same issue :)

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

8 participants