2

I'm working on a Laravel 4.2 app built with dingo/api and NeoEloquent to support Graph databases. I want to implement OAuth, probably using lucadegasperi/oauth2-server-laravel, but this doesn't work with NeoEloquent. After I created a Client in the database, when trying Authorizer::issueAccessToken() I get the following error:

exception 'League\OAuth2\Server\Exception\InvalidClientException' with message 'Client authentication failed.' in /home/vagrant/code/vendor/league/oauth2-server/src/Grant/PasswordGrant.php:114
Stack trace:
#0 /home/vagrant/code/vendor/league/oauth2-server/src/AuthorizationServer.php(275): League\OAuth2\Server\Grant\PasswordGrant->completeFlow()
#1 /home/vagrant/code/vendor/lucadegasperi/oauth2-server-laravel/src/Authorizer.php(80): League\OAuth2\Server\AuthorizationServer->issueAccessToken()
#2 /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(205): LucaDegasperi\OAuth2Server\Authorizer->issueAccessToken()

I can't find any OAuth implementation for Laravel that supports Graph databases or works with NeoEloquent. Does anyone have any idea on how to work this out?


Update

A part of my composer.json:

"require": {
        "laravel/framework": "4.2.*",
        "vinelab/neoeloquent": "*",
        "laravelbook/ardent": "~2.4",
        "doctrine/dbal": "~2.5",
        "lucadegasperi/oauth2-server-laravel": "3.*",
        "dingo/api": "0.8.*"
    },

All my models extend my own NeoArdent, which is a copy of laravelbook/Ardent with some changes in relationship definitions to make it work with NeoEloquent.

My grant types in app/config/packages/lucadegasperi/oauth2-server-laravel/oauth2.php

'grant_types' => [
    'password' => [
        'class' => '\League\OAuth2\Server\Grant\PasswordGrant',
        'callback' => function($username, $password) {
            if( Auth::validate([
                'email'    => $username,
                'password' => $password,
            ])){
                $user = User::where('email', $username)->first();
                return $user->id;
            } else {
                return false;
            }
        },
        'access_token_ttl' => 3600
    ]
]

My authentication provider definition in app/config/packages/dingo/api/config.php

'auth' => [
    'oauth' => function ($app) {
        $provider = new Dingo\Api\Auth\LeagueOAuth2Provider($app['oauth2-server.authorizer']->getChecker());

        $provider->setUserResolver(function ($id) {
            return User::findOrFail($id);
        });

        $provider->setClientResolver(function ($id) {
            return User::findOrFail($id);
        });
        return $provider;
    }
]

Before I try to get the auth code I temporarily use this to create a client:

if (!DB::table('oauth_clients')->count()) {
    $client = [
        'id' => 'angularApp',
        'secret' => 'angularAppSecret',
        'name' => 'angularApp'
    ];
    DB::table('oauth_clients')->insert($client);
}

And after that I do this:

Auth::login($user);
Input::merge(['grant_type' => 'password', 'client_id' => 'angularApp', 'client_secret' => 'angularAppSecret']);
return AuthorizerFacade::issueAccessToken();

which gives me the error above.

I hope this helps a bit in understanding my problem.

gidomanders
  • 465
  • 5
  • 16
  • The thing that you need to notice here is that there's no such thing as "integration" b/w Laravel, dingo/api and NeoEloquent, they are three different "components" of your application. It would help to post the code that is generating this error that also shows how you're using these packages together. – mulkave Mar 10 '15 at 10:47
  • I added some code to help you understand my problem a bit better. – gidomanders Mar 11 '15 at 08:53

1 Answers1

0

I couldn't wait much longer, so I just changed to using MongoDB using bmcmurray/ardent-mongodb which is a fork of laravelbook/Ardent to support jenssegers/laravel-mongodb. I used Ardent before I converted to Graph databases, then built my own fork for laravelbook/Ardent to support Vinelab/NeoEloquent, so my code doesn't change that much.

There is a lot more support on using MongoDB with OAuth, like the guy that posted this question. I'm sure I can make OAuth work now.

Community
  • 1
  • 1
gidomanders
  • 465
  • 5
  • 16