0
0
Laravelframework~5 mins

API authentication with Sanctum in Laravel - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Laravel Sanctum used for?
Laravel Sanctum provides a simple way to authenticate Single Page Applications (SPAs), mobile apps, and simple token-based APIs securely.
Click to reveal answer
beginner
How does Sanctum authenticate API requests?
Sanctum uses API tokens or cookie-based session authentication to verify the identity of the user making the request.
Click to reveal answer
intermediate
What is the purpose of the 'sanctum' middleware in Laravel?
The 'sanctum' middleware protects routes by ensuring only authenticated users with valid tokens or sessions can access them.
Click to reveal answer
intermediate
How do you create an API token for a user with Sanctum?
You call the createToken method on the user model, like: $token = $user->createToken('token-name')->plainTextToken;
Click to reveal answer
advanced
What is the difference between Sanctum's token abilities and scopes?
Abilities (or scopes) define what actions a token can perform, allowing fine-grained control over API access.
Click to reveal answer
Which Laravel package provides simple API token authentication for SPAs and mobile apps?
AJetstream
BPassport
CBreeze
DSanctum
What method do you use to generate a new API token for a user in Sanctum?
AcreateToken()
BgenerateToken()
CmakeToken()
DnewToken()
Which middleware should you apply to routes to protect them with Sanctum authentication?
Aauth:api
Bauth:sanctum
Cweb
Dguest
Sanctum tokens can have abilities. What do these abilities control?
AWhat actions the token can perform
BThe token's expiration time
CThe user's password
DThe database connection
Which of these is NOT a typical use case for Sanctum?
AAuthenticating Single Page Applications
BAuthenticating mobile apps
COAuth2 server implementation
DSimple token-based API authentication
Explain how Laravel Sanctum secures API routes and how you would protect a route using it.
Think about middleware and token validation.
You got /3 concepts.
    Describe the process to generate and use an API token with Sanctum for a user.
    Focus on token creation and usage in requests.
    You got /3 concepts.