15

you know, Laravel Passport have predefined routes as folllow:

php artisan route:list
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
| Domain | Method   | URI                                     | Name | Action                                      | Middleware   |
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
|        | GET|HEAD | /                                       |      | Closure                                     | web          |
|        | POST     | oauth/authorize                         |      | ...\ApproveAuthorizationController@approve  | web,auth     |
|        | GET|HEAD | oauth/authorize                         |      | ...\AuthorizationController@authorize       | web,auth     |
|        | DELETE   | oauth/authorize                         |      | ...\DenyAuthorizationController@deny        | web,auth     |
|        | GET|HEAD | oauth/clients                           |      | ...\ClientController@forUser                | web,auth     |
|        | POST     | oauth/clients                           |      | ...\ClientController@store                  | web,auth     |
|        | PUT      | oauth/clients/{client_id}               |      | ...\ClientController@update                 | web,auth     |
|        | DELETE   | oauth/clients/{client_id}               |      | ...\ClientController@destroy                | web,auth     |
|        | GET|HEAD | oauth/personal-access-tokens            |      | ...\PersonalAccessTokenController@forUser   | web,auth     |
|        | POST     | oauth/personal-access-tokens            |      | ...\PersonalAccessTokenController@store     | web,auth     |
|        | DELETE   | oauth/personal-access-tokens/{token_id} |      | ...\PersonalAccessTokenController@destroy   | web,auth     |
|        | GET|HEAD | oauth/scopes                            |      | ...\ScopeController@all                     | web,auth     |
|        | POST     | oauth/token                             |      | ...\AccessTokenController@issueToken        | throttle     |
|        | POST     | oauth/token/refresh                     |      | ...\TransientTokenController@refresh        | web,auth     |
|        | GET|HEAD | oauth/tokens                            |      | ...\AuthorizedAccessTokenController@forUser | web,auth     |
|        | DELETE   | oauth/tokens/{token_id}                 |      | ...\AuthorizedAccessTokenController@destroy | web,auth     |
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+

Is it possible to modify that route? e.g. oauth/authorize become api/v1/oauth/authorize

if yes, how?

I've been searching for answer quite sometime...

AnD
  • 3,060
  • 8
  • 35
  • 63

2 Answers2

25

Yes, it is. You can declare your own routes in Passport::routes() method.

Include this inside the boot() method of your app/Providers/AuthServiceProvider file.

app/Providers/AuthServiceProvider.php

public function boot()
{
    Passport::routes(null, ['prefix' => 'api/v1/oauth']);
}
Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
Egretos
  • 1,155
  • 7
  • 23
5

It seems like the routes method has been removed (Passport 11.x).

In order to do this now, you would need to publish the Passport configuration file and set the path attribute to the desired value: api/v1/oauth.

php artisan vendor:publish --tag=passport-config
// config/passport.php

<?php

return [
    ...

    'path' => 'api/v1/oauth',
];

I haven't been able to find this information in the documentation. I figured this out by looking at the source code. Here's the link for further reference.

Professor
  • 858
  • 1
  • 9
  • 17