Skip to content

Glossary

Laravel Sanctum: signing in for APIs and your own screens

Laravel's slim way of signing in apps and interfaces without running a full OAuth server.

As soon as an application consists of more than web pages, the question arises how an app or another system signs in. Sanctum is the answer Laravel ships for that. It issues access tokens, checks them on every request and can withdraw individual ones when a device goes missing.

The second use is your own interface. When the browser application and the interface belong to the same application, Sanctum carries on with the ordinary session instead of passing a token through on every call.

Why the smaller solution is usually the right one

The obvious alternative is called Passport and speaks OAuth 2.0 in full. That is the standard when outside providers are to be given access. It also brings a great deal with it that is never needed in the vast majority of projects, and every bit of it wants understanding and maintaining.

So the question is not “which is better” but “who is actually meant to sign in here”. For your own app and your own screens, Sanctum is the right size. We settle that at the beginning of an interface project; see API and backend development.

FAQ

Häufige Fragen

When do you need Passport instead?
When outside providers are meant to reach your data in the name of your users, the way you can “sign in with Google” somewhere. That is what OAuth 2.0 is for, and what Passport is for. For your own app and your own screens it is effort without return.

Related

Terms that belong with this one

A project, or a question?

Write and tell us what it is about. You get an assessment from somebody who works with Laravel themselves, not from a sales desk.