lumen-api-oauth icon indicating copy to clipboard operation
lumen-api-oauth copied to clipboard

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

Open sachinvrg opened this issue 9 years ago • 20 comments

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.

sachinvrg avatar Sep 28 '15 13:09 sachinvrg

I have the same issue, please help.

prashantidealittechno avatar Sep 30 '15 04:09 prashantidealittechno

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?

prashantidealittechno avatar Sep 30 '15 08:09 prashantidealittechno

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.

rahul9874563210 avatar Oct 01 '15 07:10 rahul9874563210

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 ?

prashantidealittechno avatar Oct 01 '15 07:10 prashantidealittechno

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] => [email protected]
    [password] => 1234
)
http://lumenoauth.dev/login/oauth/access-token

rahul9874563210 avatar Oct 01 '15 08:10 rahul9874563210

@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.

prashantidealittechno avatar Oct 12 '15 06:10 prashantidealittechno

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.

esbenp avatar Oct 17 '15 07:10 esbenp

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] => [email protected] [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

nomoregrapes avatar Nov 22 '15 20:11 nomoregrapes

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 avatar Nov 30 '15 21:11 tr33m4n

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 avatar Nov 30 '15 22:11 tr33m4n

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 avatar Nov 30 '15 22:11 tr33m4n

At least PAW/Postman works now

tr33m4n avatar Nov 30 '15 22:11 tr33m4n

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 avatar Nov 30 '15 22:11 tr33m4n

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

tr33m4n avatar Nov 30 '15 22:11 tr33m4n

@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!

Pitu avatar Dec 09 '15 19:12 Pitu

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

sachinvrg avatar Dec 10 '15 17:12 sachinvrg

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.

Pitu avatar Dec 10 '15 18:12 Pitu

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

atlcell avatar Aug 03 '16 10:08 atlcell

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

Pitu avatar Aug 04 '16 03:08 Pitu

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 :)

ghost avatar Aug 30 '16 12:08 ghost