Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change/modify predefined route in Laravel Passport?

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...

like image 820
AnD Avatar asked Oct 18 '18 12:10

AnD


People also ask

What is difference between JWT and Passport Laravel?

The "tymondesigns/jwt-auth" is a PHP Laravel implementation of the JWT protocol. On the other hand, Passport also uses JWT by default plus a huge extra, a complete Oauth2 implementation. Regarding the functionality, as I said they both use JWT thus you can use whichever you like to authentication via tokens.

What is the difference between Laravel Passport and Sanctum?

Chatty Cathy @vincent15000 Passport is an OAuth server implementation, and used to offer OAuth authorisation for your application. Sanctum is an authentication library for “simpler” token-based authentication for clients that need it (i.e. mobile apps) but also offers cookie-based authentication for SPAs.

What is the purpose of Laravel Passport?

Laravel Passport is an OAuth 2.0 server implementation for API authentication using Laravel. Since tokens are generally used in API authentication, Laravel Passport provides an easy and secure way to implement token authorization on an OAuth 2.0 server.

What is default route in Laravel?

The Default Route Files All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.


1 Answers

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']);
}
like image 167
Egretos Avatar answered Sep 19 '22 21:09

Egretos