Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 18, 2024 via composer

laravel/sanctum v3.3.3

Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.
Package summary
Share
0
issues
1
license
37
MIT
Package created
20 Mar 2020
Version published
19 Dec 2023
Maintainers
1
Total deps
37
Direct deps
4
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
37 Packages, Including:
brick/math@0.12.1
carbonphp/carbon-doctrine-types@2.1.0
doctrine/inflector@2.0.10
illuminate/bus@v10.48.10
illuminate/collections@v10.48.10
illuminate/conditionable@v10.48.10
illuminate/console@v10.48.10
illuminate/container@v10.48.10
illuminate/contracts@v10.48.10
illuminate/database@v10.48.10
illuminate/events@v10.48.10
illuminate/filesystem@v10.48.10
illuminate/macroable@v10.48.10
illuminate/pipeline@v10.48.10
illuminate/support@v10.48.10
illuminate/view@v10.48.10
laravel/prompts@v0.1.21
laravel/sanctum@v3.3.3
nesbot/carbon@2.72.3
nunomaduro/termwind@v1.15.1
psr/clock@1.0.0
psr/container@2.0.2
psr/simple-cache@3.0.0
symfony/console@v6.4.7
symfony/deprecation-contracts@v3.5.0
symfony/finder@v6.4.7
symfony/polyfill-ctype@v1.29.0
symfony/polyfill-intl-grapheme@v1.29.0
symfony/polyfill-intl-normalizer@v1.29.0
symfony/polyfill-mbstring@v1.29.0
symfony/polyfill-php80@v1.29.0
symfony/process@v6.4.7
symfony/service-contracts@v3.5.0
symfony/string@v7.0.7
symfony/translation@v6.4.7
symfony/translation-contracts@v3.5.0
voku/portable-ascii@2.0.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

4
All Dependencies CSV
ⓘ This is a list of laravel/sanctum 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
illuminate/consolev10.48.10-MIT
prod
illuminate/contractsv10.48.10-MIT
prod
illuminate/databasev10.48.10-MIT
prod
illuminate/supportv10.48.10-MIT
prod

Visualizations

Frequently Asked Questions

What does laravel/sanctum do?

Laravel Sanctum is a powerful and lightweight library that offers an effective authentication system for Single Page Applications (SPAs) and simple APIs. Laravel Sanctum is designed to provide a simple and enjoyable development experience for both beginners and experienced PHP developers. A notable feature of Laravel Sanctum is its ability to offer robust mechanisms for issuing API tokens to your application's users. It also ensures a secure SPA authentication, keeping your customer data safe and your applications running smoothly.

How do you use laravel/sanctum?

Using Laravel Sanctum involves a number of easy-to-follow steps. First, install the Laravel Sanctum via Composer:

composer require laravel/sanctum

Once installed, you must publish the Sanctum configuration and migration files using the vendor:publish Artisan command:

php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

Next, you need to run your database migrations using:

php artisan migrate

In your app/Http/Kernel.php file, you should add Laravel Sanctum’s middleware:

use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;

'api' => [
    EnsureFrontendRequestsAreStateful::class,
    'throttle:60,1',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
],

To use Sanctum's tokenCan method to authenticate certain actions, you need to add Laravel\Sanctum\HasApiTokens trait to your App\Models\User model:

use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
}

Now, you are ready to start using Laravel Sanctum. Let's login a user, and provide a token:

$user = User::find(1);

$token = $user->createToken('my-token')->plainTextToken;

return response()->json(['token' => $token]);

In your client side, simply use this token in the Authorization header:

Authorization: Bearer my-token

Where are the laravel/sanctum docs?

For a comprehensive walkthrough of Laravel Sanctum and further code examples, kindly refer to the official documentation which can be found on the Laravel website at https://laravel.com/docs/sanctum. In the documentation, you'll find additional details that cover a wider scope of the usage and integration possibilities of Laravel Sanctum.