How to use oauth2-server-laravel

I am using the oauth2-server-laravel package, I am new to oauth. I am trying to implement the Password Flow method of this library. I am stuck on how to give client_id and client_secret.

Here's my route:

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

      

This gives the answer as -

{
    "error": "invalid_request",
    "error_description": "The user credentials were incorrect."
}

      

I have pasted client_id and client_secret from mysql. Visited users table.

So why does this indicate an error in the answer? What am I doing wrong?

+3


source to share


1 answer


For newbies who want to use username instead of email (this is the advertised method in their doc), please change the following on your oauth2.php:



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

      

0


source







All Articles