In this file, I would like to overwrite some functionality of the one function in that file: AuthO Laravel Package
The package is installed as a Vendor package in the application.
I dont want to change any route functionality in the application, and I dont want to fork the package.
The above file/function runs on a callback from AuthO. All this works fine, and I run \Log::info() from the file to check that it runs the code. Assume this works as intended in the Vendor package.
I have the following custom provider:
<?php
namespace App\Providers;
use App\Services\AuthOService;
use Illuminate\Support\ServiceProvider;
class CustomAuthOServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register(): void
{
// Bind the custom controller to the original controller
$this->app->bind(\Auth0\Login\Controllers\CallbackControllerAbstract::class, AuthOService::class);
}
}
This is registered is config\app :
..
'providers' => [
App\Providers\CustomAuthOServiceProvider::class,
]
...
Then I have a service class in App\Services:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Vendor\Auth0\Login\Controllers\CallbackControllerAbstract;
// use Auth0\Login\Controllers\CallbackControllerAbstract;
class AuthOService extends CallbackControllerAbstract
{
/**
* Handle the callback from the identity provider.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function __invoke(Request $request): Response
{
\Log::info('Handling provider callback. test');
// Change the redirection URL to '/testtest'
return redirect('/testtest')->intended('/');
}
}
With all the code implementations above, there are no errors when the application runs.
But the function __invoke is not running, and the \Log is not hit in my AuthOService.php.
I have checked the following:
Overwrite Laravel vendor package
Best way to override a class inside a vendor package?
How Can I Override/Change a Vendor Class?
The above links have helped me to be at the current stage of where I am at, but now I am stuck and dont know what to do from here.
How do I overwrite/extend on the specific file mentioned at the top, in a Laravel Application, without forking or changing routes?
What I specifically want to change/overwrite is the exception on line 105:
$exception = new CallbackControllerException(sprintf(CallbackControllerException::MSG_API_RESPONSE, $error, $errorDescription));