-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DOCSP-41241: Laravel Sanctum #3050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
9c15cd0
854af26
8c5882c
3ef2184
4122cc2
e9b6a3c
bf4b643
1e49d08
2b0afbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Laravel\Sanctum\PersonalAccessToken as SanctumToken; | ||
use MongoDB\Laravel\Eloquent\DocumentModel; | ||
|
||
class PersonalAccessToken extends SanctumToken | ||
{ | ||
use DocumentModel; | ||
|
||
protected $connection = 'mongodb'; | ||
protected $collection = 'personal_access_tokens'; | ||
protected $primaryKey = '_id'; | ||
protected $keyType = 'string'; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ User Authentication | |||||||||||||
.. contents:: On this page | ||||||||||||||
:local: | ||||||||||||||
:backlinks: none | ||||||||||||||
:depth: 1 | ||||||||||||||
:depth: 2 | ||||||||||||||
:class: singlecol | ||||||||||||||
|
||||||||||||||
Overview | ||||||||||||||
|
@@ -97,8 +97,64 @@ manage user authentication, as shown in the following code: | |||||||||||||
:language: php | ||||||||||||||
:dedent: | ||||||||||||||
|
||||||||||||||
Enable Password Reminders | ||||||||||||||
------------------------- | ||||||||||||||
Customize User Authentication | ||||||||||||||
----------------------------- | ||||||||||||||
|
||||||||||||||
In this section, you can learn how to use the following features to | ||||||||||||||
customize your MongoDB user authentication process: | ||||||||||||||
|
||||||||||||||
- :ref:`laravel-user-auth-sanctum` | ||||||||||||||
- :ref:`laravel-user-auth-reminders` | ||||||||||||||
|
||||||||||||||
.. _laravel-user-auth-sanctum: | ||||||||||||||
|
||||||||||||||
Laravel Sanctum | ||||||||||||||
~~~~~~~~~~~~~~~ | ||||||||||||||
|
||||||||||||||
You can install the Laravel Sanctum package to provide API tokens to users | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: add a sentence explaining broadly what laravel sanctum is |
||||||||||||||
and authenticate single-page applications. To manage API tokens, Sanctum stores | ||||||||||||||
each token in a database table and authenticates incoming HTTP requests through | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
the ``Authorization`` header. To authenticate single-page applications, Sanctum | ||||||||||||||
uses Laravel's cookie-based authentication services. | ||||||||||||||
|
||||||||||||||
Run the following commands from your project root to install Laravel Sanctum, | ||||||||||||||
then publish and run its migration files: | ||||||||||||||
|
||||||||||||||
.. code-block:: bash | ||||||||||||||
|
||||||||||||||
composer require laravel/sanctum | ||||||||||||||
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider" | ||||||||||||||
php artisan migrate | ||||||||||||||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
|
||||||||||||||
.. tip:: | ||||||||||||||
|
||||||||||||||
To learn more about installing and configuring Laravel Sanctum, see the | ||||||||||||||
`Installation <https://laravel.com/docs/{+laravel-docs-version+}/sanctum#installation>`__ | ||||||||||||||
section of the Laravel Sanctum guide. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
To use Laravel Sanctum with {+odm-short+}, you must modify the ``PersonalAccessToken`` | ||||||||||||||
model provided by Sanctum. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: provide a little more explanation of what is required here |
||||||||||||||
|
||||||||||||||
Example | ||||||||||||||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
``````` | ||||||||||||||
|
||||||||||||||
The following code extends the ``PersonalAccessToken`` model provided by Sanctum | ||||||||||||||
to enable MongoDB: | ||||||||||||||
|
||||||||||||||
.. literalinclude:: /includes/auth/PersonalAccessToken.php | ||||||||||||||
:language: php | ||||||||||||||
:dedent: | ||||||||||||||
|
||||||||||||||
After modifying the ``PersonalAccessToken`` model, instruct Sanctum to use the custom | ||||||||||||||
model by calling the ``usePersonalAccessTokenModel()`` method in one of your application's | ||||||||||||||
service providers. To learn more, see the `Overriding Default Models | ||||||||||||||
<https://laravel.com/docs/{+laravel-docs-version+}/sanctum#overriding-default-models>`__ | ||||||||||||||
section of the Laravel Sanctum guide. | ||||||||||||||
|
||||||||||||||
.. _laravel-user-auth-reminders: | ||||||||||||||
|
||||||||||||||
Password Reminders | ||||||||||||||
~~~~~~~~~~~~~~~~~~ | ||||||||||||||
|
||||||||||||||
To add support for MongoDB-based password reminders, register the following service | ||||||||||||||
provider in your application: | ||||||||||||||
|
@@ -111,7 +167,7 @@ This service provider modifies the internal ``DatabaseReminderRepository`` | |||||||||||||
to enable password reminders. | ||||||||||||||
|
||||||||||||||
Example | ||||||||||||||
~~~~~~~ | ||||||||||||||
``````` | ||||||||||||||
|
||||||||||||||
The following code updates the ``providers.php`` file in the ``bootstrap`` directory | ||||||||||||||
of a Laravel application to register the ``PasswordResetServiceProvider`` provider: | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: before this sentence, add a sentence explaining why someone might want to make a custom model