luchavez / passport-pgt-server
Laravel Passport Password Grant Tokens Server for Laravel 8|9|10
Installs: 247
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/luchavez/passport-pgt-server
Requires
- php: ^8.0
- illuminate/support: ~8|~9|~10
- laravel/passport: ^10.4|^11.5
- luchavez/passport-pgt-client: ^2.0
Requires (Dev)
- orchestra/testbench: ~6|~7|~8
- phpunit/phpunit: ~9.0
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-10-17 11:29:02 UTC
README
Laravel Passport is an authentication package for Laravel. It is used by a lot of Laravel apps to authenticate users before accessing any resources. Basically, it generates an access token which you can then use on every request to provide identification to the OAuth Server.
One of Laravel Passport's mostly used authentication methods is the Password Grant Tokens grant type. It is a stateless way to get access tokens and refresh tokens from the OAuth Server.
Take a look at contributing.md if you want to contribute to this project.
Installation
Via Composer
// Install the package and its dependencies $ composer require luchavez/passport-pgt-server --with-all-dependencies // Publish the config, migrate Passport tables, and run passport:install $ php artisan pgt:server:install
Setting Up
- 
Run php artisan migrateto create the Passport related tables.
- 
Use Passport's Laravel\Passport\HasApiTokenson User model.
- 
Add these variables to .envfile if you want to override the default values.
| Variable Name | Default Value | 
|---|---|
| PASSPORT_ACCESS_TOKEN_EXPIRES_IN | 15 days | 
| PASSPORT_REFRESH_TOKEN_EXPIRES_IN | 30 days | 
| PASSPORT_PERSONAL_ACCESS_TOKEN_EXPIRES_IN | 6 days | 
| PASSPORT_HASH_CLIENT_SECRETS | false | 
Usage
Passport PGT Server
The package provides a service called PassportPgtServer which you can use by calling its helper functions:
- passportPgtServer()
- passport_pgt_server()
Here's the list of its available methods.
| Method Name | Return Type | Description | 
|---|---|---|
| setPassportAsApiDriver | void | adds apiauthentication guard withpassportas driver | 
| setPassportEncryptionKeys | void | used for overriding Passport encryption keys | 
| hashClientSecrets | bool | decides whether to hash or not client's secrets | 
| getTokensExpiresIn | Illuminate\Support\Carbon | gets the Carbondatetime for access token expiration | 
| getRefreshTokensExpiresIn | Illuminate\Support\Carbon | gets the Carbondatetime for refresh token expiration | 
| getPersonalAccessTokensExpiresIn | Illuminate\Support\Carbon | gets the Carbondatetime for personal access token expiration | 
| getTokenModel | string | gets the model class name | 
| getTokenBuilder | Illuminate\Database\Eloquent\Builder | gets the model builder instance | 
| getRefreshTokenModel | string | gets the model class name | 
| getRefreshTokenBuilder | Illuminate\Database\Eloquent\Builder | gets the model builder instance | 
| getPersonalAccessTokenModel | string | gets the model class name | 
| getPersonalAccessTokenBuilder | Illuminate\Database\Eloquent\Builder | gets the model builder instance | 
| getClientModel | string | gets the model class name | 
| getClientBuilder | Illuminate\Database\Eloquent\Builder | gets the model builder instance | 
Routes
By default, laravel/passport adds authentication related routes. This package adds two new routes: /api/oauth/logout and /api/oauth/me.
Here's the list of routes that this package provides.
| Method | Route | Description | 
|---|---|---|
| POST | /oauth/token | Added by laravel/passport. This route generates the tokens. | 
| GET | /api/oauth/register | This route is where we register a new user. | 
| POST | /api/oauth/logout | This route revokes the current access tokenwithrefresh token. | 
| GET | /api/oauth/me | This route returns the access token's user information. | 
Note: If you wish to override the logout or get self logic, feel free to do so by updating the published passport-pgt-server config file.
Change log
Please see the changelog for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email jamescarloluchavez@gmail.com instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.
