Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 25, 2024 via composer

laravel/sanctum v2.9.4

Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.
Package summary
Share
0
issues
1
license
26
MIT
Package created
20 Mar 2020
Version published
6 Apr 2021
Maintainers
1
Total deps
26
Direct deps
3
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
26 Packages, Including:
carbonphp/carbon-doctrine-types@3.2.0
doctrine/inflector@2.0.10
illuminate/collections@v8.83.27
illuminate/container@v8.83.27
illuminate/contracts@v8.83.27
illuminate/database@v8.83.27
illuminate/macroable@v8.83.27
illuminate/support@v8.83.27
laravel/sanctum@v2.9.4
nesbot/carbon@2.72.3
psr/clock@1.0.0
psr/container@1.1.2
psr/simple-cache@1.0.1
symfony/console@v5.4.39
symfony/deprecation-contracts@v3.5.0
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-php73@v1.29.0
symfony/polyfill-php80@v1.29.0
symfony/service-contracts@v3.5.0
symfony/string@v6.4.7
symfony/translation@v6.4.7
symfony/translation-contracts@v3.5.0
voku/portable-ascii@1.6.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

3
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/contractsv8.83.27-MIT
prod
illuminate/databasev8.83.27-MIT
prod
illuminate/supportv8.83.2783.71 kBMIT
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.