Oauth2-server-laravel user response

I am using Oauth-server-laravel Authentication.

What i have done so far:

When I send the wrong one access_tokento the API that I created in laravel, it gives the following answer,

{
  "error": "access_denied",
  "error_description": "The resource owner or authorization server denied the request."
}

I used oauthas middleware in the following order,

Route::group(['namespace' => 'Modules\User\Http\Controllers', 'middleware' => 'oauth'], function () {

    // Get User Profile Details
    Route::post('getUserProfileDetail', 'UserController@getUserProfileDetail');
});

Problem:

If the credentials are incorrect, then oauth will automatically respond with a default message, and I want to configure these response messages,

I have half the success in the fact that if the credentials are correct, then it calls the function specified in the route, and that I add the mre response that I want to send.

$response = $this->authorizer->issueAccessToken();

$code = 200; //Response OK
$response['result'] = 'success';
$response['user_id'] = $user['id'];
$response['email'] = $user['email'];
$response['name'] = $user['name'];

, , .

+4
1

, ( , )]

, app/Http/Middleware. OauthExceptionMiddleware

app/Http/kernel.php

oauth2 $middleware,

protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \App\Http\Middleware\OauthExceptionMiddleware::class,
    ];

Oauth2

<?php
/**
 * Created by PhpStorm.
 * User: kingpabel
 * Date: 3/23/16
 * Time: 4:40 PM
 */
namespace app\Http\Middleware;
use Closure;
use League\OAuth2\Server\Exception\OAuthException;
class OauthExceptionMiddleware
{
    public function handle($request, Closure $next)
    {
        try {
            $response = $next($request);
            // Was an exception thrown? If so and available catch in our middleware
            if (isset($response->exception) && $response->exception) {
                throw $response->exception;
            }
            return $response;
        } catch (OAuthException $e) {
            $data = [
//                'error' => $e->errorType,
//                'error_description' => $e->getMessage(),
                'error' => 'Custom Error',
                'error_description' => 'Custom Description',
            ];
            return \Response::json($data, $e->httpStatusCode, $e->getHttpHeaders());
        }
    }
}
+1