Home > Net >  Laravel API Sanctum or Passport
Laravel API Sanctum or Passport

Time:05-19

I want create Laravel API and NextJS app. Separate applications.

But, my back-end will be connect to 3th party API. From this 3th party API i will get a token that will allow me to communicate with this API in the next requests.

Overall:

  • My NextJS front
  • My Laravel API
  • 3th party API (Rest, Oauth2)

The question is:

The way I authenticate points first and second (my app and api) affects my API's communication second point with the third point ?

Can i use Sanctum or Passport in communication beetwen first point /second ?

CodePudding user response:

If your front-end(NextJS) only communicates with (Laravel)API i.e SPA, the Sanctum should do the job. Passport is more suitable if API needs to be consumed(resources needs to be consumed/managed) on behalf of a user that is where OAuth2 comes into picture.

Their doc is pretty straight-forward. https://laravel.com/docs/9.x/passport#passport-or-sanctum

Backend communication i.e between your Laravel and 3rd Party APIs will not impact Sanctum. In this case, 3rd Party will issue credentials/token so not related.

CodePudding user response:

If there is no direct communication from your FE to 3rd party APIs then you can use either Sanctum or Passport in your Laravel API project. As a general practice avoid to call 3rd parties directly from FE and create an API for that in your Laravel API project and call that API from FE.

  • Related