laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Way to use Sanctum and Laravel's authentication without requiring laravel/ui #2107

Open chrisbbreuer opened 4 years ago

chrisbbreuer commented 4 years ago

I have been playing around with Sanctum for quite a while now and I think it's great and working properly, too.

In my scenario, Laravel is only handling the API and the frontend is ran on a vue-cli project. The possible improvement I am thinking about is the fact that I would like to reuse backend logic from the laravel/ui package (ResetsPasswords, AuthenticatesUsers, etc.), but have it be extracted out of the ui package.

Why am I thinking this?

For me, it's tough to wrap my head around requiring a "UI" package into a project that's solely an API.

I am thinking along the lines of:

php artisan make:auth --api

This command could:

  1. require Sanctum (if it's part of the Laravel core framework or else it could be part of the Sanctum package itself)
  2. pull in the proper auth controllers and traits for all of Laravel's built-in auth related functionalities (reset passwords, login, logout, token creation, email verification, etc.)
  3. generate the corresponding API routes needed for all auth related actions

I think this is a very common scenario and Sanctum helps tremendously already, but I feel like we could bootstrap even more. Being able to generate a fully functioning API authentication system as we can do for the frontend would be a timesaver.

Am I overthinking this? Am I missing anything? What's your approach if you had to build an API and wanted to reuse Laravel's authentication?

Best,

Chris

rockyxcoded commented 4 years ago

@Chris1904 I was about to open the same issue, I support your thinking.

quanengineering commented 4 years ago

@Chris1904 I also need this as soon as possible <3

semivori commented 4 years ago

@Chris1904 I also need this

JoeBocock commented 4 years ago

@Chris1904 This would be great!

D4RKAR117 commented 4 years ago

@Chris1904 this must be awesome, i support the idea

RonanOFM commented 4 years ago

@Chris1904 Good idea

chrisbbreuer commented 4 years ago

While I agree this could be a great idea, before I would start any development for this I would prefer to know beforehand whether this is something that @driesvints or Taylor could consider merging into core.

Part of the reason I am hesitant to start development for this feature is the fact that php artisan make:auth was removed a few versions back and I am not sure whether there is any interest in bringing any form of it back. Nonetheless, if there is no interest, there may be alternative approaches to include this functionality.

In the meantime, though, for anyone coming here, as it seems like a somewhat popular request, we are currently developing a boilerplate that makes use of these ideas are built-in: https://github.com/ci-on/laravel-nuxt-tailwind-boilerplate/

At the time of this writing, it's not perfectly done yet, but it should get you pretty far, especially if you use Laravel & Nuxt 😎 As a bonus & because of our love for Tailwind, it's obviously included as well.

baj84 commented 3 years ago

I am currently trying to implement reset passwords for my restful api. I really don't want to require the whole UI scaffolding for an api project, so it would be great to be able to do this.

I haven't been able to find any good tutorials on how to reset a password purely from a restful API :/

Eerey commented 3 years ago

Great idea. I had the exact same thought. Support the request!