-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the ability to use package with service-to-service Passport cl…
…ient (#2467) * Adding the ability to use package with service-to-service Passport clients Co-authored-by: SuperDJ <[email protected]> Co-authored-by: erikn69 <[email protected]>
- Loading branch information
1 parent
2dc2787
commit 04a9592
Showing
14 changed files
with
538 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
title: Passport Client Credentials Grant usage | ||
weight: 12 | ||
--- | ||
|
||
**NOTE** currently this only works for Laravel 9 and Passport 11 and newer. | ||
|
||
## Install Passport | ||
First of all make sure to have Passport installed as described in the [Laravel documentation](https://laravel.com/docs/master/passport). | ||
|
||
## Extend the Client model | ||
After installing the Passport package we need to extend Passports Client model. | ||
The extended Client model should look like something as shown below. | ||
|
||
```php | ||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; | ||
use Illuminate\Foundation\Auth\Access\Authorizable; | ||
use Laravel\Passport\Client as BaseClient; | ||
use Spatie\Permission\Traits\HasRoles; | ||
|
||
class Client extends BaseClient implements AuthorizableContract | ||
{ | ||
use HasRoles; | ||
use Authorizable; | ||
|
||
public $guard_name = 'api'; | ||
|
||
// or | ||
|
||
public function guardName() | ||
{ | ||
return 'api' | ||
} | ||
} | ||
``` | ||
|
||
You need to extend the Client model to make it possible to add the required traits and properties/ methods. | ||
The extended Client should either provide a `$guard_name` property or a `guardName()` method. | ||
They should return a string that matches the [configured](https://laravel.com/docs/master/passport#installation) guard name for the passport driver. | ||
|
||
## Middleware | ||
All middlewares provided by this package work with the Client. | ||
|
||
Do make sure that you only wrap your routes in the [`client`](https://laravel.com/docs/master/passport#via-middleware) middleware and not the `auth:api` middleware as well. | ||
Wrapping routes in the `auth:api` middleware currently does not work for the Client Credentials Grant. | ||
|
||
## Config | ||
Finally, update the config file as well. Setting `use_passport_client_credentials` to `true` will make sure that the right checks are performed. | ||
|
||
```php | ||
// config/permission.php | ||
'use_passport_client_credentials' => true, | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.