laravel-api-boilerplate icon indicating copy to clipboard operation
laravel-api-boilerplate copied to clipboard

Suggestion: Auth0 implementation

Open egdavid opened this issue 6 years ago • 21 comments

Any thoughts on implementing the Laravel Auth0 package ? Auth0 is regularly used by api consumers and it could be great making endpoints compatible with this authentication system.

egdavid avatar Jun 01 '19 21:06 egdavid

Hey there

Thanks for the suggestion, it is actually on the cards to make this package integrated with Passport, and so I will add Auth0 to that as well :+1:

specialtactics avatar Jun 02 '19 08:06 specialtactics

@specialtactics thanks for the answer.

I've integrated the Auth0 JWT management and I can now login using Auth0 (Facebook, Google or anything else) and use the TokenId to call API boilerplate's endpoints.

I'm just worried about a little thing: can you confirm that I can completely get rid of the api.auth middleware ? Since my SPA wont use or make any crud request for the users table on my Laravel api.

egdavid avatar Jun 03 '19 09:06 egdavid

@roasted-toast I am not use, the underlying dingo package relies on api.auth, if you replace it, then whatever you replace it with has to provide an equivalent implementation of authentication, and work with helpers like auth()

specialtactics avatar Jun 04 '19 00:06 specialtactics

@specialtactics +1 for https://laravel.com/docs/master/passport I know Auth0 makes it simple also but I have no idea why indie makers and devs would use it, they charge per user, and it's not cheap either 🗡 Out of curiosity what does this repo use now for API auth, if not passport?

connecteev avatar Jul 20 '19 12:07 connecteev

A JWT Auth system is implemented within the boilerplate.

egdavid avatar Jul 21 '19 08:07 egdavid

@egdavid got it. Love to see support for Laravel passport.

connecteev avatar Jul 21 '19 09:07 connecteev

It will definitely come, do not worry guys :smile:

Right now the main trouble for me is that there's a lot of work on the roadmap, and trying to priorotise the easy wins.

Right now, the built-in JWT will suffice for 80% of use cases. Next, I want to write HMAC authentication, which will take some effort because I don't think there are any maintained laravel auth hmac implementations, but it's very useful for APIs.

Down the track a bit will be passport and/or auth0.

specialtactics avatar Jul 21 '19 23:07 specialtactics

@specialtactics I could create a PR of my own implementation of Auth0 if you want.

egdavid avatar Jul 22 '19 00:07 egdavid

@egdavid If you've integrated it into the boilerplate, I would definitely love to see !

So long as it won't break any existing functionality and can be turned on/off, it should be fine.

specialtactics avatar Jul 22 '19 02:07 specialtactics

@specialtactics in this particular case it will require some changes, there is no way to turn it on or off for example and I'm not sure it would not break the existing JWT auth system since I "got rid" of it. However, I could try to produce a decent Pull Request for your boilerplate, asap (within the next week or so). P.S.: this implementation will require a documentation to explain how M2M auth actually works with Laravel and how it needs to be set @ Auth0. It has not be well detailed by Auth0 in their doc, I had to do some extra researches by myself.

egdavid avatar Jul 22 '19 07:07 egdavid

No problem @egdavid , there's no rush for sure, as I myself wouldn't get to it for months. If you feel like contributing, it would be very welcome.

Dingo itself has configurable auth providers, I think that's the place to start to make it swappable.

specialtactics avatar Jul 22 '19 07:07 specialtactics

@specialtactics I'm about to publish a PR with my own implementation of Auth0. You should probably create a Dev branch so I could publish it without affecting the main one?

egdavid avatar Aug 16 '19 15:08 egdavid

@egdavid Sure, I've pushed a "dev" branch, based off the latest master. Can't wait to see!

specialtactics avatar Aug 17 '19 03:08 specialtactics

@specialtactics I'm updating the code based on the latest master and my public (unauthenticated) routes don't work anymore. It happens only on endpoints that don't require authentication while being unauthenticated. As soon as I log in (on Postman), it works. Here is the error:

{
    "message": "Call to a member function can() on null",
    "statusCode": 500,
    "debug": {
        "line": 98,
        "file": "/home/david/Sites/apiboilerplatenew/vendor/specialtactics/l5-api/src/Http/Controllers/Features/AuthorizesUserActionsOnModelsTrait.php",

Any idea? It used to work before the boilerplate update. Models haven't been updated.

EDIT: seems like I've had some issues with my custom API Policies. I've removed them for the incoming push.

egdavid avatar Aug 29 '19 14:08 egdavid

So did you fix the issue @egdavid ? I would advise, if you have unauthenticated routes, the model used by those controllers can't have a policy, since there wouldn't be any logged in user to check any access policies against.

specialtactics avatar Sep 02 '19 11:09 specialtactics

Hey guys, +1 on this. Any updates?

mroushdy avatar Apr 02 '20 22:04 mroushdy

No updates sorry, not a priority unfortunately at the moment !

specialtactics avatar Apr 02 '20 22:04 specialtactics

How compatible is this boiler plate if laravel changes in the future but the boiler plat did not? Are the changes to laravel a lot? Or is it mostly outside of changes to the laravel framework?

On Thu, Apr 2, 2020 at 3:41 PM Max [email protected] wrote:

No updates sorry, not a priority unfortunately at the moment !

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/specialtactics/laravel-api-boilerplate/issues/19#issuecomment-608128879, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOOX7PU2NWCJHRNT7APRXTRKUIBPANCNFSM4HSBLGWQ .

mroushdy avatar Apr 03 '20 00:04 mroushdy

@mroushdy Nothing of laravel is changed actually, it all works through packages and inheritance. It's the same version of Laravel as any other.

specialtactics avatar Apr 03 '20 06:04 specialtactics

Hello Dear Thanks for the great work. Kindly help if you have time, when I run composer test it gives me this error. I have mysql I dont use POSTGRES

./vendor/bin/phpunit --colors=always -v --testdox PHPUnit 9.5.12 by Sebastian Bergmann and contributors.

Error in bootstrap script: Illuminate\Database\QueryException: could not find driver (SQL: select tablename from pg_catalog.pg_tables where schemaname in ('public')) Script ./vendor/bin/phpunit --colors=always -v --testdox handling the test event returned with error code 1

Master-maynd avatar Feb 20 '22 08:02 Master-maynd

@Master-maynd mysql should be the default indeed, let's make sure it's set like that

  • The default driver in config/database.php should be mysql
    • 'default' => env('DB_CONNECTION', 'mysql'),
  • The DB_CONNECTION in .env should be set to mysql
    • DB_CONNECTION=mysql
  • Make sure that in phpunit.xml you are not overriding the DB_CONNECTION setting above

If it all fails I suggest

  • to compare your branch against the boilerplate as spot the diffs
  • Push your code to a pubic repo (if possible) or post your configs here

michaelvaes avatar Feb 20 '22 09:02 michaelvaes