Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uccdev's avatar

Laravel Route Authentication: "Route [login] not defined"?

Hi,

I'm developing software in Laravel and Passport that uses OAuth2 authentication with Canvas. It's to authenticate users, admins and non-users and see if they've permission to access a page.

However, when I try to make a request on this route, I get the following error message:

    Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined.

I don't understand why. Nowhere in my code do I call a "login" route, anywhere. Could anyone please offer some clarity on the subject? I'd be most grateful.

If it's of any use, here is my code in laravel for the route request:

    Route::get('/testClient', ['as' => 'testClient', 'uses' => function(Request $request) {
       $http = new GuzzleHttp\Client;
       $response = $http->post('https://my.test.instructure.com/login/oauth2/auth?client_id=9&response_type=code&redirect_uri=http://www.google.com', [
          'form_params' => [
             'grant_type' => 'authorization_code',
             'client_id' => 9,
             'client_secret' => 'my_secret',
             'redirect_uri' => 'www.google.com',
          ],
       ]);
       return json_decode((string) $response->getBody(), true)['access_token'];
    }])->middleware('client');
0 likes
5 replies
Nakov's avatar

search for route('login') in your IDE you are obviously using it somewhere to get this error.

Jaytee's avatar

Check that client middleware file too. Could be causing a redirect, or redirecting after it's successful

1 like
uccdev's avatar

@jaytee Thanks for your reply. The 'client' middleware is following the instructions of the Passport documentation here https://laravel.com/docs/6.x/passport#client-credentials-grant-tokens

I've added to app/Http/Kernel.php:

  use Laravel\Passport\Http\Middleware\CheckClientCredentials;

  protected $routeMiddleware = [
      'client' => CheckClientCredentials::class,
  ];

I can confirm that this these two mentions are the only references to CheckClientCredentials in my project. I'm not sure what to make of this.

uccdev's avatar
uccdev
OP
Best Answer
Level 2

Nakov,

Thanks for linking that. While it did not have the answer, it helped me lead to it.

One of the major problems I had was that I hadn't configured the middleware correctly. I'd put the middleware definitions inside $middleware when they should have been in $routeMiddleware. Thank you for your help!

Please or to participate in this conversation.