Ted
Ted

Reputation: 4166

Laravel 4 API with OAuth 2

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?

Upvotes: 1

Views: 3087

Answers (3)

renz
renz

Reputation: 3

Did you try those commands?

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

Upvotes: 0

David Barker
David Barker

Reputation: 14620

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

Upvotes: 4

Robin
Robin

Reputation: 132

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();

Upvotes: 2

Related Questions