laravel / passport

Laravel Passport provides OAuth2 server support to Laravel.
https://laravel.com/docs/passport
MIT License
3.28k stars 776 forks source link

[Feature] Allow configuration of login redirect route via config #1708

Closed robertmarney closed 8 months ago

robertmarney commented 8 months ago

Closes #1704

Description:

Allow developers to override the opinion of where unauthenticated users are redirected to for login.

This is particularly useful in cases where the application has multiple guards in place.

Implementation:

  1. Introduce new config property to store the custom login route.
  2. Introduce new make function on the existing Laravel\Passport\Exceptions\AuthenticationException and use the existing redirectTo argument.
  3. Replace all existing throw new AuthenticationException with throw AuthenticationException::make()
  4. Update existing tests with the requisite mocks
  5. Introduce new test for this explicit functionality
taylorotwell commented 8 months ago

Catch the exception in your application's exception handler's render method and return the redirect from there.