Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Passport Grant Tokens vs Sanctum API Token Authentication

Hello,

I used Sanctum API Token recently, but I never coded anything with Passport.

I have a Laravel / VueJS application for which I can't use the Sanctum SPA Authentication : I have to use the Sanctum API Token Authentication.

This way I need to store the token in the browser, which is not secure.

According to another port where @martinbean answered, Passport seems to be a solution with Authorization Code Grant With PKCE. It seems to be great, but I really need to authenticate a user with an email and a password.

When I read the documentation, Passport Grant Tokens do that, but it's no longer recommended to use it.

https://laravel.com/docs/11.x/passport#password-grant-tokens

So I have some questions to better understand how it works :

  • is it more secure to use Passport Grant Tokens instead of Sanctum API Token Authentication ?

  • is it possible to authenticate with email / password credentials with Authorization Code Grant With PKCE ?

  • is there another way to authenticate with Passport with email / password credentials ?

Thanks for your help.

V

0 likes
7 replies
martinbean's avatar

Is it more secure to use Passport Grant Tokens instead of Sanctum API Token Authentication ?

@vincent15000 As you’ve mentioned, you shouldn’t be using the password grant type. It’s completely disallowed in the latest OAuth spec: https://oauth.net/2/grant-types/password/

is it possible to authenticate with email / password credentials with Authorization Code Grant With PKCE ?

This is how you authenticate. With OAuth, you get a token. How do you get the token? By the user authenticating and approving the request. You should be redirecting to your Laravel application, the user should be prompted to log in if they’re not logged in already, and when they approve the request they will be redirected back to your SPA with an OAuth access token to use for subsequent API requests. This is what the /oauth/authorize route does: https://laravel.com/docs/11.x/passport#code-grant-pkce-redirecting-for-authorization

is there another way to authenticate with Passport with email / password credentials ?

See above.

1 like
vincent15000's avatar

@martinbean I have read the entire documentation of Passport, but it is still confusing for me.

Can you explain me some steps please ?

According to the documentation, I have to do in order :

Sorry for all these questions, but OAuth is all new for me.

Thanks for your help.

V

martinbean's avatar
Level 80

php artisan passport:client --public => what is a client ?

@vincent15000 A client is what issues tokens. You can have multiple clients for multiple applications. So you could have a client for your web application, a client for an iOS app, a client for an Android app, and so on.

https://laravel.com/docs/11.x/passport#code-grant-pkce-redirecting-for-authorization => how should I use the /redirect route ? then if the user approves the authorization request, ok but how is he able to approve the authorization request ? I don't understand where could be any button he can click on to approve

The docs (https://laravel.com/docs/11.x/passport#code-grant-pkce-redirecting-for-authorization) explain the process:

Once a client has been created, you may use the client ID and the generated code verifier and code challenge to request an authorization code and access token from your application. First, the consuming application should make a redirect request to your application's /oauth/authorize route

So, you redirect your user to /oauth/authorize. It then builds a URL to redirect the user to. The URL will start with /oauth/authorize, is provided by Passport, and will prompt the user to log in (if they’re not already authenticated) and to authorise the client. By default, it will return this view. As you can see, it’s similar to the pages you get when authorising access to say, your Google or Facebook account, where you get a screen saying “[Some App] wants to use your account”. When the user approves the request, they’ll be redirected back to the original app (your SPA) with an OAuth access token that your SPA can use to make API requests as that user.

https://laravel.com/docs/11.x/passport#code-grant-pkce-converting-authorization-codes-to-access-tokens => return $response->json(); I don't see any token in the response, and what do I have to do in the frontend when I receive this response ?

Again, the docs (https://laravel.com/docs/11.x/passport#code-grant-pkce-converting-authorization-codes-to-access-tokens) covers this step.

1 like
vincent15000's avatar

@jlrdw Thank you, very interesting documentation to better understand how OAuth works.

Please or to participate in this conversation.