1593304309
Recently I needed to tap on Laravel’s Passport programming to control how the JSON Web Tokens (JWT) were being issued. Specifically, I needed to add more claims to it (to hold more user information) and to control how the scopes were being generated. The idea was to add information like the authenticated user’s email, VAT number, account type, and, also, to forcibly add the scopes that were associated with the user’s role.
However, changing Laravel Passport’s behavior to make it happen isn’t quite obvious, and in a world were service-oriented architectures are becoming ever more common, JWT being the de facto way of carrying user’s information through multiple services, and since I couldn’t find quite a good resource to understand how to do it, I thought I could share with you how I approached and solved my own problem.
I’m developing ITsoup, an IT support/helpdesk software system, designed to simplify and streamline all its related processes, based in a service-oriented architecture. This means that I’ll have many services that handle specific domains of work. In order to authenticate the requests, properly, I needed some way of holding users’ information in a way that could be passed around from service to service. The de facto way of doing this is with JWTs, so I started investigating how I could make those changes to the JWT generation logic.
The problem with current Laravel Passport implementation is that it only includes one identification claim for the user: it’s internal ID. That’s not of much use for me on this project. Using only the ID would require any other services to request any additional user information to the Organization Domain service’s API if they need, for example, the e-mail.
Doing that way would create an unwanted, unnecessary, dependency between this service and all others that work with the user’s data and would increase the load on this Organization Domain service as new services and/or traffic increased.
Before anything, I like to always understand what’s going on under the hood. By getting a broader context of the system I need to change, I can make informed decisions on how to approach a solution.
As far as I understood, it all goes down on Laravel\Passport\PassportServiceProvider
. Here we can find the registerAuthorizationServer()
method, which is responsible for defining how Laravel instantiates the AuthorizationServer
class and registers the supported oAuth2 authorization grants. But before that happens, there’s a call to a makeAuthorizationServer()
method. This method is the one that’s responsible to define how the AuthorizationServer
gets instantiated, and injects the proper dependencies from the Laravel’s Container!
The key class to this whole thing is the Bridge\AccessTokenRepository
, which is one of the dependencies injected. Since it’s being injected via the Container, we can take advantage of it an inject our own instance of that class, instead. This class has a very special method, getNewToken()
, which is called when an enabled authorization grant needs to generate a new token.
Hooking to the logic flow, here, and direct it through our own implementation of the AccessTokenRepository
class enables us to control how the JWT is created, the information it holds, and many other aspects of it.
#oauth2 #software-engineering #programming #php #laravel
1624255260
Today, we will see Laravel 8 PDF Generate Example.
For generating PDF file we will use Laravel-dompdf package, it is create pdf file and also provide to download file functionalities it is very easy to generate pdf in laravel 8, i will give you example in very simple way to generate pdf file and download in your system.
So, Let’s start and see how to generate pdf in laravel 8.
#laravel 8 pdf generate example #laravel 8 #pdf generate #generate pdf in laravel 8 #laravel-dompdf package #how to generate pdf in laravel 8
1597817005
Bar Code Generate in Laravel 7, 6. In this post, i will show you simple and easy steps to generate bar/qr code in laravel.
Use the below given steps and generate bAR/QR codes in laravel Projects:
https://www.tutsmake.com/laravel-6-simple-generate-or-create-qr-codes-example/
#laravel 7 bar code generator #barcode generator laravel 7 #barcode generator laravel 6 #laravel 7 qr code generator #laravel simple/barcode example
1624438819
CMARIX is one of the leading Laravel web development company at this time with a rating of 4.9/5 on Clutch. This is the best place where you could probably find the Best Laravel developers in the industry. Being one of the top Laravel development companies, CMARIX aims to create an atmosphere of collaboration, creativity, and excellence where everyone is doing their best work.
#laravel web development company india #laravel development services india #laravel web development company #laravel framework development services #laravel development #laravel development company
1597489568
In this post, i will show you how to dynamically add/remove multiple input fields and submit to database with jquery in php laravel framework. As well as, i will show you how to add/remove multiple input fields and submit to database with validation in laravel.
dynamically add remove multiple input fields and submit to database with jquery and laravel app will looks like, you can see in the following picture:
Follow the below given easy step to create dynamically add or remove multiple input fields and submit to database with jquery in php laravel
#laravel - dynamically add or remove input fields using jquery #dynamically add / remove multiple input fields in laravel 7 using jquery ajax #add/remove multiple input fields dynamically with jquery laravel #dynamically add multiple input fields and submit to database with jquery and laravel #add remove input fields dynamically with jquery and submit to database #sql
1595201363
First thing, we will need a table and i am creating products table for this example. So run the following query to create table.
CREATE TABLE `products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Next, we will need to insert some dummy records in this table that will be deleted.
INSERT INTO `products` (`name`, `description`) VALUES
('Test product 1', 'Product description example1'),
('Test product 2', 'Product description example2'),
('Test product 3', 'Product description example3'),
('Test product 4', 'Product description example4'),
('Test product 5', 'Product description example5');
Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = [
'name','description'
];
}
Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.
routes/web.php
Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);
#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete