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?
✗ Incorrect
Sanctum is designed for simple token-based authentication, especially for SPAs and mobile apps.
What method do you use to generate a new API token for a user in Sanctum?
✗ Incorrect
The createToken() method on the user model generates a new API token.
Which middleware should you apply to routes to protect them with Sanctum authentication?
✗ Incorrect
The auth:sanctum middleware ensures routes are accessible only to authenticated users via Sanctum.
Sanctum tokens can have abilities. What do these abilities control?
✗ Incorrect
Abilities define permissions or scopes for what the token is allowed to do.
Which of these is NOT a typical use case for Sanctum?
✗ Incorrect
OAuth2 server implementation is handled by Laravel Passport, not Sanctum.
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.