Skip to content

Commit fd30e09

Browse files
committed
edits, code file
1 parent 93a3d90 commit fd30e09

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use MongoDB\Laravel\Passport\AuthCode;
7+
8+
class AppServiceProvider extends ServiceProvider
9+
{
10+
/**
11+
* Register any application services.
12+
*/
13+
public function register(): void
14+
{
15+
//
16+
}
17+
18+
/**
19+
* Bootstrap any application services.
20+
*/
21+
public function boot(): void
22+
{
23+
Passport::useAuthCodeModel(AuthCode::class);
24+
}
25+
}

docs/user-authentication.txt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ Laravel Passport is an OAuth 2.0 server implementation that offers
164164
API authentication for Laravel applications. Use Laravel Passport if
165165
your application requires OAuth2 support.
166166

167+
Install Laravel Passport
168+
````````````````````````
169+
167170
To install Laravel Passport and run the database migrations required
168171
to store OAuth2 clients, run the following command from your project root:
169172

@@ -212,10 +215,23 @@ to the ``guards`` array:
212215
],
213216
],
214217

215-
Lastly, you must override the default Laravel Passport models by defining a custom model
216-
that extends the corresponding Laravel Passport model. by including the ``DocumentModel`` trait. This trait allows you
217-
to make Laravel Passport compatible with MongoDB. The following code defines
218-
a series of model classes that extend the corresponding ``Laravel\Passport`` models:
218+
Use Laravel Passport with {+odm-short+}
219+
```````````````````````````````````````
220+
221+
After installing Laravel Passport, you must enable Passport compatibility with MongoDB by
222+
defining custom {+odm-short+} models that extend the corresponding Passport models.
223+
To extend each Passport model class, include the ``DocumentModel`` trait in the custom models.
224+
You can define the following {+odm-short+} model classes:
225+
226+
- ``MongoDB\Laravel\Passport\AuthCode``, which extends ``Laravel\Passport\AuthCode``
227+
- ``MongoDB\Laravel\Passport\Client``, which extends ``Laravel\Passport\Client``
228+
- ``MongoDB\Laravel\Passport\PersonalAccessClient``, which extends ``Laravel\Passport\PersonalAccessClient``
229+
- ``MongoDB\Laravel\Passport\RefreshToken``, which extends ``Laravel\Passport\RefreshToken``
230+
- ``MongoDB\Laravel\Passport\Token``, which extends ``Laravel\Passport\Token``
231+
232+
For example, the following code overrides the default ``Laravel\Passport\AuthCode``
233+
model class by defining a ``MongoDB\Laravel\Passport\AuthCode`` class and including
234+
the ``DocumentModel`` trait:
219235

220236
.. code-block:: php
221237

@@ -227,10 +243,14 @@ a series of model classes that extend the corresponding ``Laravel\Passport`` mod
227243
protected $keyType = 'string';
228244
}
229245

230-
class MongoDB\Laravel\Passport\Client extends Laravel\Passport\Client;
231-
class MongoDB\Laravel\Passport\PersonalAccessClient extends Laravel\Passport\PersonalAccessClient;
232-
class MongoDB\Laravel\Passport\RefreshToken extends Laravel\Passport\RefreshToken;
233-
class MongoDB\Laravel\Passport\Token extends Laravel\Passport\Token;
246+
After defining a custom model, instruct Passport to use the model in the ``boot``
247+
method of your application's ``App\Providers\AppServiceProvider`` class, as shown
248+
in the following code:
249+
250+
.. literalinclude:: /includes/auth/PersonalAccessToken.php
251+
:language: php
252+
:emphasize-lines: 6,23
253+
:dedent:
234254

235255
You can now use Laravel Passport and MongoDB in your application. For more information, see
236256
`Laravel Passport <https://laravel.com/docs/{+laravel-docs-version+}/passport>`__ in the

0 commit comments

Comments
 (0)