Which one should i use among these. laravel/sanctum or laravel/passport or jwt-auth?

Viewed 7323

I am developing a very big "xyz.com" application. application will have multiple subdomains hosted in multiple servers like "abc.xyz.com" & "def.xyz.com", etc. All of the servers are driven by "laravel-package-development". "xyz" frontend will be SPA and backend will be API-driven. I guess there will 10-20 laravel-packages-developed. and all laravel-pacakages-developed may have their own auth-system. I have doubt in which "package" to use for API-authentication. My considerations for auth-packages are as follows: a. Laravel/Passport or b. Laravel/Sanctum or c. Jwt-Auth.(Sean Tymon) My concerns are as follows:

  1. Scalability & Support of library for newer php versions like php v8.
  2. Security.
  3. multi-domains access of APIs via token. and multi-domains cookie-session-management.
  4. "Package" repos should have fewer issues.
  5. mostly i will not need oAuth2.
  6. package development. I have worked on all a, b, c "packages" from laravel v5.5 to v8.x. Since entire "xyz" application is very very big, i would like to be very sure regarding what "package" i should use. Anyone with experience, please suggest which "package" to use. I vote for "sanctum". ANY SUGGESTION IS HIGHLY APPRECIATED
1 Answers

Any of these packages will work well but If you want to get updates faster and support without any concern in the future and also the best compatibility and speed, I think the laravel/sanctum or passport is the best. They have so many features but I prefer passport because it's good for handling multi-auth projects and it's a handful package.

e.x: passport simply lets you share cookies (even sessions) with other domains by some config in the .env file. So when a user logged in with laravel you will store some cookies and pass them to other domains as an active user (authenticated user).

Passport provides a full OAuth2 server implementation for your Laravel application in a matter of minutes. It needs to have a brief knowledge about OAuth2.

Sanctum is a simple package to issue API tokens to your users without the complication of OAuth. Sanctum uses Laravel's built-in cookie-based session authentication services.

If your application absolutely needs to support OAuth2, then you should use Laravel Passport.

However, if you are attempting to authenticate a single-page application, mobile application, or issue API tokens, you should use Laravel Sanctum. Laravel Sanctum does not support OAuth2; however, it provides a much simpler API authentication development experience.

Related