I am just inserting the http cache on my silex project doing this:
// http cache
$this->register(new \Silex\Provider\HttpCacheServiceProvider(), array(
'http_cache.cache_dir' => $this->getConfig()['http_cache_service']['cache_dir'],
));
$this is an owner class that it extends from Silex Application.
And my routing is:
// homepage
$this->get('/', function (Request $request) use ($app) {
return new Response($app['twig']->render('index/index.html.twig', []), 200, [
'Cache-Control' => 's-maxage=500'
]);
})->bind('homepage');
And I run my application in this mode:
\Symfony\Component\HttpFoundation\Request::setTrustedProxies(array('127.0.0.1','localhost','192.168.2.11'));
$app['http_cache']->run();
I am following the steps written in http://silex.sensiolabs.org/doc/master/providers/http_cache.html
But, when I load the 'homepage' the X-Symfony-Cache is always miss.
I am using Apache2 with PHP7, and I don't have installed any inversed proxy as Varnish, because I understand that it is not mandatory because HttpCacheServiceProvider is enough by itself.
Related
My aim is to integrate an okta sso app that uses saml2 protocol. My project is built upon laravel and I'm using this package to help me integrate saml2. As per the docs I have implemented the following:
Added configuration to config/services.php
'saml2' => [
'acs' => 'http://dashboard.test/okta-saml-callback',
'entityid' => 'http://www.okta.com/exk7qiudmbjsr*******',
'certificate' => 'MIIDqDCCApCgAwIBAgIGAYU+Ux31MA0GCSqGSIb3DQEBCwUAMIGUMQswCQYDVQQGEwJVUzETMBEG.......'
]
Added provider event listener as such
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\SocialiteProviders\Saml2\Saml2ExtendSocialite::class.'#handle',
],
];
Added the authflow
Route::get('/okta-saml-login', function () {
return Socialite::driver('saml2')->redirect();
})->name('saml.login');
And finally the callback URL
Route::get('/okta-saml-callback', function () {
$user = Socialite::driver('saml2')->user();
dd($user);
});
After configuration, when I hit the '/okta-saml-login' route, instead of it redirecting me to the okta login pop up page for SSO, I get a 404 not found page. Which means there is something wrong with the auth URL. Now I tried to search the documentation but did not find anything about configuring auth URL anywhere.
I have a problem with my routes on the server and using laravel 8, with a version of php 8.0.6
When developing locally I have no problem with the routes, everything is normal, but when uploading the project to the server (to which I do not have access but someone else uploads the changes from the repository) it throws me the following error in some views...
Error 404
In my code I have the routes declared as follows in the routes/web.php file...
Route::get('/home', 'PagesController#home');
Each view has a function that comes from the controller...
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PhpParser\Node\Expr\FuncCall;
class PagesController extends Controller
{
public function home()
{
$page_title = 'Dashboard';
return view('pages.dashboard', compact('page_title'));
}
}
On the other hand, each route can be accessed through a menu aside
// Aside menu
return [
'items' => [
// Dashboard
[
'title' => 'Dashboard',
'root' => true,
'icon' => 'media/svg/icons/Design/Layers.svg', // or can be 'flaticon-home' or any flaticon-*
'page' => '/home',
'new-tab' => false,
]
]
]
I tried :
correct writing to avoid mistakes
change "/" in each affected path
note: they told me the server was in strict mode
I want only my payment checkout pages in https. I have a website in http://, I´m implement a payment checkout with Stripe credit card, but Stripe only works with https...
I want that all my website have http, except the /payment-date page and the payment-data-post page, to send the data to Stripe with secure protocol.
How I can have only those two pages on https?
The routes are:
Route::get('/payment-data',['as'=> 'payment_data','uses' => 'WebController#getPaymentData']);
Route::post('/post-payment-data', ['as' => 'post_payment_data', 'uses' => 'WebController#postPaymentData']);
I want only this routes in https
The framework is Laravel 5.3
I think a good practice would be to create a Middleware which you then can use on whatever routes you'd like.
Using your Terminal, navigate to your project’s root directory and issue the following artisan command (to create ForceHttpProtocol middleware):
php artisan make:middleware ForceHttpProtocol
Change the newly created /app/Http/Middleware/ForceHttpProtocol.php so it looks something like this (will work only on production):
<?php
namespace App\Http\Middleware;
use Closure;
class ForceHttpProtocol {
public function handle($request, Closure $next) {
if (!$request->secure() && env('APP_ENV') === 'pro') {
return redirect()->secure($request->getRequestUri());
}
return $next($request);
}
}
Next step is to update /app/Http/Kernel.php by adding the 'App\Http\Middleware\ForceHttpProtocol' which will make Laravel aware of your custom middleware.
If you want to apply middleware only on specific routes, you just have to assign middleware to routes by adding 'App\Http\Middleware\ForceHttpProtocol' instruction to $routeMiddleware array.
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
...
'forceSSL' => App\Http\Middleware\ForceHttpProtocol::class,
];
Just use the newly created middleware as you’re used to:
Route::get('payment-date', ['middleware' => 'forceSSL', function()
{
// do stuff
}]);
That should be it!
You can specify if routes should be HTTP or HTTPS by passing ['http' => true] or ['https' => true] as options when declaring your routes, if you don't specify those options then it should just use the same protocol as you're currently accessing the page with.
Route::post('/form', ['uses' => 'FormController#postForm', 'https' => true]);
I am trying to figure out a problem I have. I have 2 laravel setups on the same server, each are independent sites controlled via vhosts.
SiteA needs to act as an API to SiteB. So within SiteA I set up an API by doing
Route::group(['prefix' => 'api/v1'], function () {
Route::post('postProject', array('as' => 'postProject', 'uses' => 'APIController#postProject'));
});
For now, the controller function is simply this
public function postProject(Project $project)
{
dd($project);
}
So within SiteB I want to call this API. As such, I set up a route which contains the project object (I have tried both get and post)
Route::get('projects/{projects}/postProject', array('as' => 'projects.postProject', 'uses' => 'APIController#postProject'));
And this controller function does the following
public function postProject($project)
{
$client = new GuzzleHttp\Client();
$req = $client->request('POST', 'http://localhost/api/v1/postProject', [
'body' => $project,
'headers' => [
'Content-Type' => 'text/xml',
'Content-Length' => strlen($project),
]
]);
$output = $req->getBody()->getContents();
return $output;
}
I have localhost as an example url so the real url wasnt exposed. The error siteB receives when making the post request is a 404 not found. If on siteA I set up a simple get function that returns something, siteB can execute this API call without any problem. The problem comes about when I am trying to post something from siteB to siteA.
Additionally, when I pass the $project object, is there any way to send over its related models as well? A $project has one to many relationships with a few other models, and ideally I would like to get the related data over.
I think you just need to eager load the relationships
public function postProject()
{
//dd($project);
Project::with('relation1', 'relation2')->find($id);
}
I try to use the package Laravel\Socialite in my system in Lumen (5.1)
I added this in the config\services.php file :
<?php
//Socialite
'facebook' => [
'client_id' => '##################',
'client_secret' => '##################',
'redirect' => 'http://local.dev/admin/facebook/callback',
],
In bootstrap\app.php file :
class_alias(Laravel\Socialite\Facades\Socialite::class, 'Socialite');
$app->register(Laravel\Socialite\SocialiteServiceProvider::class);
Then I created a controller for the facebook authentication :
<?php
namespace App\Http\Controllers\Facebook;
use App\Http\Controllers\Controller;
use Laravel\Socialite\Contracts\Factory as Socialite;
class FacebookController extends Controller
{
public function redirectToProviderAdmin()
{
return Socialite::driver('facebook')->scopes(['manage_pages', 'publish_actions'])->redirect();
}
public function handleProviderCallbackAdmin()
{
$user = Socialite::driver('facebook')->user();
}
}
And in the routes.php :
$app->get('/admin/facebook/login', 'App\Http\Controllers\Facebook\FacebookController#redirectToProviderAdmin');
$app->get('/admin/facebook/callback', 'App\Http\Controllers\Facebook\FacebookController#handleProviderCallbackAdmin');
I just followed the documentation, changing according to my needs. When I go to page http://local.dev/admin/facebook/login, I get the following error :
Non-static method Laravel\Socialite\Contracts\Factory::driver() cannot be called statically, assuming $this from incompatible context
Indeed, according to the code, driver function must be instanciate.
EDIT : And if I try to instanciate this class, I get the following error :
Cannot instantiate interface Laravel\Socialite\Contracts\Factory
How do you make this module to work?
here's how that works in my case
in services.php file
'facebook' => [
'client_id' => '***************',
'client_secret' => '***************',
'redirect' => ""
],
i left redirect empty cause my site is multilingual (so, it fills in a bit later with sessions). if you use only one language, put there your callback absolute path. for example
"http://example.com:8000/my-callback/";
also check your config/app.php. in providers array
Laravel\Socialite\SocialiteServiceProvider::class,
in aliases array
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
my routes look like this
Route::get('facebook', 'Auth\AuthController#redirectToProvider');
Route::get('callback', 'Auth\AuthController#handleProviderCallback');
here's auth controllers methods. put in top
use Socialite;
//იობანი როტ
public function redirectToProvider(Request $request)
{
return Socialite::with('facebook')->redirect();
}
public function handleProviderCallback(Request $request)
{
//here you hadle input user data
$user = Socialite::with('facebook')->user();
}
my facebook app
giga.com:8000 is my localhost (so its the same localhost:8000)
as you can see in Valid OAuth redirect URI, you should put there your callback. in my case i use three urls cause i have three languages. in your case it should be just
http://your-domain-name.com:8000/callback
if you work on localhost, you should name your domain in config/services.php
mine look like this
'domain' => "your-domain.com",
after everything run these commands
php artisan cache:clear
php artisan view:clear
composer dump-autoload
restart your server, clear your browser cookies. hope it helps