Download the PHP package xcoorp/laravel-passport-control without Composer
On this page you can find all versions of the php package xcoorp/laravel-passport-control. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xcoorp/laravel-passport-control
More information about xcoorp/laravel-passport-control
Files in xcoorp/laravel-passport-control
Package laravel-passport-control
Short Description Resource Server package for Laravel Passport.
License MIT
Homepage https://github.com/xcoorp/laravel-passport-control
Informations about the package laravel-passport-control
Introduction
Passport Control is a Laravel Passport compatible, OAuth2 resource server package.
This package is meant to be used in a Laravel application that is acting as a Resource Server only e.g. an API server that is meant to authenticate against an Authentication Server running Laravel Passport.
This project does not depend on the Laravel Passport package itself, but it does share some of the same concepts and interfaces.
Table of Contents
- Installation
- Pre-requisites
- Composer
- Configuration
- Usage
- Advanced Usage
- Testing
- Code of Conduct
- License
Installation
The installation of this package is quite straightforward. But before you start, make sure you have the pre-requisites in place.
Pre-requisites
This package assumes, you have already installed and configured Laravel Passport in your Laravel application. Once you have done this, you need to create a new client with client credentials grant type on your Passport Server.
Follow the official Laravel Passport documentation on how to do this.
Once you have done this, set the PASSCONTROL_INTROSPECTION_CLIENT_ID
and PASSCONTROL_INTROSPECTION_CLIENT_SECRET
environment variables
accordingly.
As of now, Laravel does not Ship with an introspection endpoint. So you need to create one manually. You can do this by installing the Laravel Passport Introspection package on your Passport Server:
Once you have done this an introspection Endpoint will be available for your Laravel application, you can now continue with the installation of this package.
[!TIP] If you need more information on how to install and configure the introspection package, check out its documentation.
Composer
You can simply install the package via composer:
Once the package is installed, you should publish the configuration and migration files:
and run the migrations:
Configuration
This package comes with a configuration file that you can and should customize to your needs.
The configuration file is located at config/passport-control.php
.
All configuration options (except the User Model) can be also configured via environment variables instead of the configuration file.
The following Environment variables are available:
Environment Variable | Value | Default |
---|---|---|
PASSCONTROL_CREATE_USER | Whether this package should create a user in the local db if not existent. | false |
PASSCONTROL_INTROSPECTION_ENDPOINT | The Introspection Endpoint URL. Usually $YOUR_PASSPORT_SERVER/oauth/introspect | http://localhost/oauth/introspect |
PASSCONTROL_ACCESS_TOKEN_ENDPOINT | The Token Endpoint URL to receive a new access token. Usually $YOUR_PASSPORT_SERVER/oauth/token | http://localhost/oauth/token |
PASSCONTROL_ACCESS_TOKEN_CLIENT_ID | Client Id needed to get the access token for introspection. Check Pre-requisites for more information. | |
PASSCONTROL_ACCESS_TOKEN_CLIENT_SECRET | Client Secret needed to get the access token for introspection. Check Pre-requisites for more information. | |
PASSCONTROL_PUBLIC_KEY_PATH | Path where the public key file oauth-public.key is stored. NOTE: Specify the path without the filename. |
Laravel Storage Path (storage) |
PASSCONTROL_INHERIT_SCOPES | In Laravel Passport, you can configure that the scopes are inherited from the parent client, set to true if you have passport configured that way. | False |
PASSCONTROL_CACHE_STORE | Cache Storage used for storing the Client Credential Access Token | CACHE_STORE , file |
PASSCONTROL_CACHE_PREFIX | Cache Prefix used for storing the Client Credential Access Token | xcoorppasscontrol |
Usage
After you have installed and configured the package, you need to configure your auth guard to be passport_control.
In your config/auth.php
file, you can add a new guard configuration like this:
That's it, now you can protect your API routes as usual by using the auth:api
middleware.
Advanced Usage
In certain circumstances, you may want to automatically create a user in your local db, if there is none.
If you want so you can enable this package to do this via the config. In that case, after success authentication,
if no user is found in your local db, one is created. (PASSCONTROL_CREATE_USER
).
[!TIP] Only the user
id
field is filled, all other fields must be either nullable or have default values.
Testing
Functionality of this package is tested with Pest PHP. You can run the tests with:
Code of Conduct
In order to ensure that the community is welcoming to all, please review and abide by the Code of Conduct.
Security Vulnerabilities
Please review the security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-passport-control with dependencies
symfony/psr-http-message-bridge Version ^7.1.1
nyholm/psr7 Version ^1.8.1
league/oauth2-server Version ^9.0.0
illuminate/auth Version ^11.0
illuminate/contracts Version ^11.0
illuminate/container Version ^11.0
illuminate/http Version ^11.0
illuminate/support Version ^11.0
illuminate/config Version ^11.0