laravel Interface 'JsonSerializable' not found - jsonserializer

Im using the following for my application for social media login
https://github.com/madewithlove/laravel-oauth2
but im getting this error
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Interface 'JsonSerializable' not found
open: /Applications/AMPPS/www/docsearch/vendor/madewithlove/laravel-oauth2/src/OAuth2/Token/Access.php
* #package OAuth2
* #category Token
* #author Phil Sturgeon
* #copyright (c) 2011 HappyNinjas Ltd
*/
class Token_Access extends Token implements \JsonSerializable
{
/**
* #var string access_token

This isn't actually a Laravel issue, it's to do with your version of PHP. If you look at the official PHP documentation you'll see that this particular interface is only available for PHP versions 5.4 and up.
Source: http://php.net/manual/en/class.jsonserializable.php

Related

"AuthenticatorInterface" not found on Security\Guard, Symfony 6.2

I'm trying to create a custom Token authenticator for my Symfony 6.2 and API Platform project
class TokenAuthenticator extends JWTTokenAuthenticator
{
/**
* #param PreAuthenticationJWTUserToken $preAuthToken
* #param UserProviderInterface $userProvider
* #return UserInterface
*/
public function getUser($preAuthToken, UserProviderInterface $userProvider): UserInterface
{
$user = parent::getUser($preAuthToken, $userProvider);
var_dump($preAuthToken->getPayload());exit;
}
}
But I always get this error:
Attempted to load interface "AuthenticatorInterface" from namespace "Symfony\Component\Security\Guard".
Did you forget a "use" statement for "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface"?
that means, there's no AuthenticatorInterface on Security\Guard and Http\Authenticator replaces it, so the LexikJWTAuthenticationBundle must be updated to include the new change.
This new class contains new functions so is there any documentation regarding them? Also, the purpose of establishing this class TokenAuthenticator is to make the old token invalid when changing the password, so is there a better way to do this?

Doctrine - Set $id as UUID instead of Integer when creating new entity

I am working on a new project in Symfony 5.3. I am using this command bin/console make:entity for creating entities.
This wizard automatically creates an entity with $id as primary key of type integer. I am prefering UUID instead of integer.
How I should change settings to get Entity like this?
Thank you
namespace App\Entity;
use App\Repository\EventRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
/**
* #ORM\Entity(repositoryClass=EventRepository::class)
*/
class Event
{
/**
* #ORM\Id
* #ORM\Column(type="uuid", unique=true)
* #ORM\GeneratedValue(strategy="CUSTOM")
* #ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private $id;
...
}
There is no option to set the generated identifier strategy on make entity.
You can see all available option using php bin/console make:entity -h
Also there are no configuration in doctrine.yaml file to define this.
It could be a good feature to add for current and next version
To request a new feature, you can create a new issue feature request type:
https://github.com/symfony/symfony/issues/new/choose
You will need a github account

How can I add CORS middleware to routes defined in custom Laravel Nova tool?

I'm building a headless cms using laravel nova and vuejs.
I'm having an issue with trying to register the excellent CORS middleware from https://github.com/barryvdh/laravel-cors. I can get this working from the main app but I would like to add this as a dependency to my custom nova tool.
I just can't figure out how to do this.
I've tried adding the middleware in the routes function generated by the artisan nova:tool command.
/**
* Register the tool's routes.
*
* #return void
*/
protected function routes()
{
if ($this->app->routesAreCached()) {
return;
}
Route::middleware(\Barryvdh\Cors\HandleCors::class)
->prefix('api/meta-blog')
->group(__DIR__.'/../routes/api.php');
}
But I get an error Class Barryvdh\Cors\HandleCors does not exist from vendor/laravel/framework/src/Illuminate/Container/Container.php when I hit any of the api paths.
I think this is because the middleware is not registered with the main app. I'm looking to find out how to make this 3rd party nova tool dependency work with the main laravel routing system.
I have successfully used other 3rd party packages with success. But not this one. I can confirm that the package exists and has been loaded in my custom tools autoload file.
Thanks in advance.
I solved this.
In the boot function we can push a middleware to the api group.
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
...
$router = $this->app['router'];
$router->pushMiddlewareToGroup('api', Barryvdh\Cors\HandleCors::class);
}
Then in the routes function
/**
* Register the tool's routes.
*
* #return void
*/
protected function routes()
{
if ($this->app->routesAreCached()) {
return;
}
Route::prefix('api/meta-blog')
->group(__DIR__.'/../routes/api.php');
}
Hope this helps someone else.

owner check not working with JWT auth

I'm following the example / documentation closely trying to set up a resource that only its owner can access, and I get this error:
"hydra:description": "Notice: Undefined property:
ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator::$owner",
JWT authentication per se seems to work fine.
my resource is defined like this:
/**
* #ORM\Entity
* #ApiResource(
* attributes={"access_control"="is_granted('ROLE_USER') and object.owner == user"},
* collectionOperations={"get"},
* itemOperations={"get"},
* )
*/
Security and user provider and everything is set up exactly as in the api-platform or Symfony documentation.
The property owner is defined as:
/**
* #var User The owner
*
* #ORM\ManyToOne(targetEntity=User::class)
*/
public $owner;
What am I doing wrong?
I think this would work on your itemOperation GET, but not on your collectionOperation. The reason is that "object" in this case will the the collection of User objects, which is represented as the Paginator class.
#ahaaje is correct.
But you can still achieve what you're looking for by implementing an "extension". This would allow you to filter the collection with only items that belong to your user.
Official documentation is here.

REST_Controller.php is not working in codeigniter

I am going to use REST_Controller.php to make rest api's. (using codeigniter v3 on ubnatu 15)
from link https://github.com/chriskacerguis/codeigniter-restserver
on calling
localhost/rest_api_ci/api/example/user/1
Showing me error
Fatal error: Class 'REST_Controller' not found in /var/www/html/rest_api_ci/application/controllers/api/Example.php on line 21
A look of Example.php file
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
/** #noinspection PhpIncludeInspection */
require(APPPATH.'libraries/REST_Controller.php');
/**
* This is an example of a few basic user interaction methods you could use
* all done with a hardcoded array
*
* #package CodeIgniter
* #subpackage Rest Server
* #category Controller
* #author Phil Sturgeon, Chris Kacerguis
* #license MIT
* #link https://github.com/chriskacerguis/codeigniter-restserver
*/
class Example extends REST_Controller {
function __construct()
{
change your url from
localhost/rest_api_ci/api/example/user/1
to
http://localhost/rest_api_ci/index.php/api/Example/users
Removing Unnecessary Namespaces in REST_Server.php and Format.php helped me.
After
require(APPPATH.'libraries/REST_Controller.php');
you need to add the namespace:
// use namespace
use Restserver\Libraries\REST_Controller;
... I ran into this issue few minutes ago and it worked with me
I think its the path issue, same answer is given here Hope it will help you or someone else.
Thanks

Resources