1
votes

I work on project based on Laravel 4 and I will provide Rest API, want to authenticate request using OAuth 2,

I try https://packagist.org/packages/lucadegasperi/oauth2-server-laravel

but when try to run

Route::post('oauth/access_token', function()
{
    return AuthorizationServer::performAccessTokenFlow();
});

I recieved

Class 'AuthorizationServer' not found

how to solve this? or there are another tool?

3

3 Answers

4
votes

You haven't followed the installation instructions provided by the package.

oauth2-server-laravel on GitHub

Add the following line to your composer.json file:

"lucadegasperi/oauth2-server-laravel": "1.0.x"

Add this line of code to the providers array located in your app/config/app.php file:

'LucaDegasperi\OAuth2Server\OAuth2ServerServiceProvider',

And these lines to the aliases array:

'AuthorizationServer' => 'LucaDegasperi\OAuth2Server\Facades\AuthorizationServerFacade', 'ResourceServer' => 'LucaDegasperi\OAuth2Server\Facades\ResourceServerFacade',

2
votes

Check if the AuthorizationServer is in another Namespace. If this is the case, use that Namespace before the class name, e.g. Namespace\AuthorizationServer::performAccessTokenFlow();

If that doesn't work, try adding a \ before the class name, like this: \AuthorizationServer::performAccessTokenFlow();

0
votes

Did you try those commands?

  • composer update
  • composer dumpautoload
  • php artisan dump-autoload