Download the PHP package zanichelli/idp-extensions without Composer
On this page you can find all versions of the php package zanichelli/idp-extensions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zanichelli/idp-extensions
More information about zanichelli/idp-extensions
Files in zanichelli/idp-extensions
Package idp-extensions
Short Description Classes to interact with the Zanichelli identity provider
License MIT
Informations about the package idp-extensions
Zanichelli IDP Laravel Extension packages
This is Laravel package to use with laravel-jwt-idp (Github: https://github.com/ZanichelliEditore/laravel-jwt-idp).
How to integrate package in your project
Step 1 - Install by Composer
Note:you should use tag instead of branch-name (e.g. "zanichelli/idp-extensions:V1.0.0" or "zanichelli/idp-extensions:dev-{branch-name}" )
Step 2 - .env file
Add this lines at bottom of your .env file:
If you need to use your own login form (instead of the IDP one), please add this line too:
These variables are read only through the idp config (config('idp.base_url'), config('idp.login_url'), config('idp.cookie.name')), so the package works with php artisan config:cache. If you published config/idp.php from an older version, the missing keys are merged automatically from the package defaults.
Step 3 - auth.php editing
Edit config/auth.php as follow:
- In
'defaults'array change value of'guard'from'web'to'z-session'
Step 4 - publish migrations
There are 2 migration from this package, Grants table and Sessions Table.
and select the "zanichelli/idp-extension" provider
Step 4.A - publish migrations (BREAKING CHANGES) after v3.0.*
There are 3 migrations from this package:
- Grants table
- Sessions Table
- Grants table key changes (Change role_id and department_id to role_name and department_name).
Using the command below will only apply the changes about role_id and department_id
Use
if you need to overwrite grants table changes migration.
Step 5 - create route middleware and protect your routes
For Laravel up to version 10:
In Kernel.php file add "idp" in your routeMiddleware
For Laravel from version 11:
Kernel.php file is no more. Register your middleware in 'bootstrap/app.php'
The default behaviour also retrieves the user's permissions (with_permissions) and remove token from query params (without_token_url)
When a token authenticates a user other than the one already in the session (a login), the middleware regenerates the session id and the CSRF token and destroys the previous session record, to prevent session fixation. Requests that replay a token for the user already in the session keep their session id.
You can specify different configuration like this:
Avoid to remove token from url
Avoid to retrieve permission
Avoid to remove token from url and retrieve permission
Add to your route file (tipically web.php) the new middleware idp; code smells like this:
Alternatively, two middlewares read the cookie and, if found, retrieves the user's data and adds it to the request
IdpApiMiddleware retrieves user's data from v1 user api call
IdpApiJWKSMiddleware retrieves user's data from jwt token
Extends IDP middleware
In order to edit retrive permissions or add extra parameter to user object you can extend default class IDP Middleware.
Class must implement following methods:
-
retrievePermissions: this method take userId and roles array as input, here role-based permissions must be retrieved to output an array of strings with permissions; addExtraParametersToUser: this method allow you to add extra parameters to the user object given as input.
After class creation, add in kernel.php file the new middleware class in '$routeMiddleware' array:
Logout idp
Create a logout route inside web.php file using a logout method inside the controller.
Implement the code as follow:
Then define logout:
Basics
With this integration you could use some Laravel's feature that allows to handle users and their authentication.
Auth is authtentication class that Laravel ships for this purpose and allow access to following methods:
Auth::check(): returnstrueif a user is authenticated,falseotherwiseAuth::guest(): returnstrueif a user is guest,falseotherwiseAuth::user(): returns aZUserclass instance,nullotherwiseAuth::id(): returnsuserIdif authtenticated,nullotherwiseAuth::hasUser(): returnstrueif there's a ZUser in our current session,falseotherwiseAuth::setUser($ZUser): sets aZuserin sessionAuth::attempt($credentials, $remember): try to login with IDP without using the login form, if success returnstrue, otherwisefalseAuth::logout(): logout a user, returnredirect
All versions of idp-extensions with dependencies
guzzlehttp/guzzle Version ~7.0
firebase/php-jwt Version ^7.0