Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when I merge it into dingo/api project , I lost -_-! #72

Closed
kency opened this issue Mar 5, 2018 · 7 comments
Closed

when I merge it into dingo/api project , I lost -_-! #72

kency opened this issue Mar 5, 2018 · 7 comments

Comments

@kency
Copy link

kency commented Mar 5, 2018

I used the project dingo/api to drive apis, after configed lumen-passport follow by the doument, the route middleWare of auth in dingo/api is 'api.auth' ,so i changed it in Dusterio\LumenPassport\RouteRegistrar. some likes
$this->app->group(['middleware' => ['api.auth']], function () {....
and just pass it in middleWare
and then I required my test method and some laravel passport method likes oauth/clients with use api.auth middleWare ,with the HTTP header :
'Accept:application/json' and
'Authorization:Bearer aExistTokenInDB'
but all of them throw a error 500

 {
     "message":"Type error: Argument 1 passed to Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException::__construct() must be of the type string, null given, called in /XXXX/vendor/dingo/api/src/Auth/Auth.php on line 113",
     "status_code":500,
    "debug":{
        "line":26,
        "file":"/XXXX/vendor/symfony/http-kernel/Exception/UnauthorizedHttpException.php",
         "class":"Symfony\Component\Debug\Exception\FatalThrowableError",
         "trace":[
             "#0 /XXXX/vendor/dingo/api/src/Auth/Auth.php(113): Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException->__construct(NULL, 'Failed to authe...')",
             "#1 /XXXX/vendor/dingo/api/src/Auth/Auth.php(96): Dingo\Api\Auth\Auth->throwUnauthorizedException(Array)",
             "#2 /XXXX/vendor/dingo/api/src/Http/Middleware/Auth.php(52): Dingo\Api\Auth\Auth->authenticate(Array)",
            "#3 /XXXX/vendor/illuminate/pipeline/Pipeline.php(149): Dingo\Api\Http\Middleware\Auth->handle(Object(Dingo\Api\Http\Request), Object(Closure))",
            "#4 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Dingo\Api\Http\Request))",
            "#5 /XXXX/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Dingo\Api\Http\Request))",
            "#6 /XXXX/vendor/illuminate/pipeline/Pipeline.php(102): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Dingo\Api\Http\Request))",
            "#7 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(410): Illuminate\Pipeline\Pipeline->then(Object(Closure))",
            "#8 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(256): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))",
            "#9 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(160): Laravel\Lumen\Application->handleFoundRoute(Array)",
            "#10 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(413): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}()",
            "#11 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(166): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))",
            "#12 /XXXX/vendor/dingo/api/src/Routing/Adapter/Lumen.php(102): Laravel\Lumen\Application->dispatch(Object(Dingo\Api\Http\Request))",
            "#13 /XXXX/vendor/dingo/api/src/Routing/Router.php(512): Dingo\Api\Routing\Adapter\Lumen->dispatch(Object(Dingo\Api\Http\Request), 'v3')",
            "#14 /XXXX/vendor/dingo/api/src/Http/Middleware/Request.php(126): Dingo\Api\Routing\Router->dispatch(Object(Dingo\Api\Http\Request))",
            "#15 /XXXX/vendor/illuminate/pipeline/Pipeline.php(114): Dingo\Api\Http\Middleware\Request->Dingo\Api\Http\Middleware\{closure}(Object(Dingo\Api\Http\Request))",
            "#16 /Users/kency/workspace/website/localsite/mashupapi.com/newLumen/mashupapi/app/Http/Middleware/Authenticate.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Dingo\Api\Http\Request))",
            "#17 /XXXX/vendor/illuminate/pipeline/Pipeline.php(149): App\Http\Middleware\Authenticate->handle(Object(Dingo\Api\Http\Request), Object(Closure))",
            "#18 /XXXX/vendor/illuminate/pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Dingo\Api\Http\Request))",
            "#19 /XXXX/vendor/dingo/api/src/Http/Middleware/Request.php(127): Illuminate\Pipeline\Pipeline->then(Object(Closure))",
            "#20 /XXXX/vendor/dingo/api/src/Http/Middleware/Request.php(103): Dingo\Api\Http\Middleware\Request->sendRequestThroughRouter(Object(Dingo\Api\Http\Request))",
            "#21 /XXXX/vendor/illuminate/pipeline/Pipeline.php(149): Dingo\Api\Http\Middleware\Request->handle(Object(Dingo\Api\Http\Request), Object(Closure))",
            "#22 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))",
            "#23 /XXXX/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))",
            "#24 /XXXX/vendor/illuminate/pipeline/Pipeline.php(102): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))",
            "#25 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(410): Illuminate\Pipeline\Pipeline->then(Object(Closure))",
            "#26 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(166): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))",
            "#27 /XXXX/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(107): Laravel\Lumen\Application->dispatch(NULL)",
            "#28 /Users/kency/workspace/website/localsite/mashupapi.com/newLumen/mashupapi/public/index.php(28): Laravel\Lumen\Application->run()",
            "#29 {main}"
        ]
    }
}

how to config it and how to use it next...I LOST.
i'm so sorry to create this issue here, if any one also use the project dingo/api ,can you suggest a running ,correct, succesful solution?

@kency
Copy link
Author

kency commented Mar 6, 2018

done

@anonman123456
Copy link

Can you explain what to look for? I'm having the same exception.

@kency
Copy link
Author

kency commented Apr 5, 2018

i wrote a wrong routes code format,you can pass it like this:

$api = app('Dingo\Api\Routing\Router');

$api->version('v3', function ($api) {
  $api->get('/b',['middleware' => 'api.auth'], function ($api) {
   //
  });
  $api->group(['middleware' => 'api.auth'], function ($api) {
         $api->get('users/{id}', 'App\Controllers\ExampleController@show');
      });
});

or:

$api->group(['middleware' => 'api.auth'], function ($api) {
         $api->get('users/{id}', 'App\Api\Controllers\ExampleController@show');
      });

or:

$api->get('/a',['middleware' => 'api.auth'], function ($api) {
  //
  });

@ayolana
Copy link

ayolana commented Apr 13, 2018

For now, I fix with using jwt.auth instead of api.auth in the route middleware.

$this->app->group(['middleware' => 'jwt.auth'], function () {....

@kency
Copy link
Author

kency commented Apr 14, 2018

FORMAT, not . ['middleware' => ['api.auth']] ,it's ['middleware' => 'api.auth']
the 'middleware' is a string, not a array in dingoapi

@ayolana
Copy link

ayolana commented Apr 14, 2018

Sorry, My bad. Fixed

@kency
Copy link
Author

kency commented Apr 14, 2018

enjoy

@kency kency closed this as completed May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants