@@ -14,7 +14,7 @@ User Authentication
1414.. contents:: On this page
1515 :local:
1616 :backlinks: none
17- :depth: 1
17+ :depth: 2
1818 :class: singlecol
1919
2020Overview
@@ -97,8 +97,62 @@ manage user authentication, as shown in the following code:
9797 :language: php
9898 :dedent:
9999
100- Enable Password Reminders
101- -------------------------
100+ Customize User Authentication
101+ -----------------------------
102+
103+ You can customize your authentication files to align with your application's
104+ needs and enable additional authentication features.
105+
106+ This section describes how to use the following features to customize the MongoDB user
107+ authentication process:
108+
109+ - :ref:`laravel-user-auth-sanctum`
110+ - :ref:`laravel-user-auth-reminders`
111+
112+ .. _laravel-user-auth-sanctum:
113+
114+ Laravel Sanctum
115+ ~~~~~~~~~~~~~~~
116+
117+ Laravel Sanctum is an authentication package that can manage API requests and
118+ single-page application authentication. To manage API requests, Sanctum issues
119+ API tokens that are stored in the database and authenticates incoming HTTP
120+ requests by using the ``Authorization`` header. To authenticate single-page applications,
121+ Sanctum uses Laravel's cookie-based authentication services.
122+
123+ You can install Laravel Sanctum to manage your application's authentication
124+ process. Run the following commands from your project root to install Laravel
125+ Sanctum and publish its migration file:
126+
127+ .. code-block:: bash
128+
129+ composer require laravel/sanctum
130+ php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
131+
132+ To use Laravel Sanctum with {+odm-short+}, modify the ``PersonalAccessToken`` model provided
133+ by Sanctum to use the ``DocumentModel`` trait from the ``MongoDB\Laravel\Eloquent`` namespace.
134+ The following code modifies the ``PersonalAccessToken`` model to enable MongoDB:
135+
136+ .. literalinclude:: /includes/auth/PersonalAccessToken.php
137+ :language: php
138+ :dedent:
139+
140+ Next, run the following command to modify the database schema:
141+
142+ .. code-block:: bash
143+
144+ php artisan migrate
145+
146+ You can now instruct Sanctum to use the custom ``PersonalAccessToken`` model by calling
147+ the ``usePersonalAccessTokenModel()`` method in one of your application's
148+ service providers. To learn more, see `Overriding Default Models
149+ <https://laravel.com/docs/{+laravel-docs-version+}/sanctum#overriding-default-models>`__
150+ in the Laravel Sanctum guide.
151+
152+ .. _laravel-user-auth-reminders:
153+
154+ Password Reminders
155+ ~~~~~~~~~~~~~~~~~~
102156
103157To add support for MongoDB-based password reminders, register the following service
104158provider in your application:
@@ -111,7 +165,7 @@ This service provider modifies the internal ``DatabaseReminderRepository``
111165to enable password reminders.
112166
113167Example
114- ~~~~~~~
168+ ```````
115169
116170The following code updates the ``providers.php`` file in the ``bootstrap`` directory
117171of a Laravel application to register the ``PasswordResetServiceProvider`` provider:
0 commit comments