Laravel Passport Simple API Authentication - Laravel-passport Typing CST Test
Loading…
Laravel Passport Simple API Authentication — Laravel-passport Code
Demonstrates a simple Laravel API protected using Passport with routes for retrieving user data.
// routes/api.php
use IlluminateSupportFacadesRoute;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
// App/Models/User.php
use LaravelPassportHasApiTokens;
class User extends Authenticatable {
use HasApiTokens, Notifiable;
}
// AuthServiceProvider.php
use LaravelPassportPassport;
public function boot() {
$this->registerPolicies();
Passport::routes();
}Laravel-passport Language Guide
Laravel Passport is an OAuth2 server implementation for API authentication in Laravel applications, providing a full OAuth2 server setup with minimal configuration.
Primary Use Cases
- ▸API authentication with OAuth2
- ▸Secure SPA and mobile application backends
- ▸Third-party API integrations
- ▸Token-based authorization and access control
- ▸Rapid implementation of secure API endpoints
Notable Features
- ▸OAuth2 server implementation
- ▸Personal access tokens for individual users
- ▸Password grant and client credentials support
- ▸Token expiration and revocation management
- ▸Seamless integration with Laravel Auth system
Origin & Creator
Created and maintained by Taylor Otwell as part of the Laravel ecosystem.
Industrial Note
Laravel Passport is used in enterprise APIs, SaaS applications, mobile backends, and SPAs where secure token-based authentication and OAuth2 compliance are required.