Laravel SAML (laravel-saml2) - Config Issues - php

I'm trying to get SSO working on an application, first time doing anything with this type of thing and falling at first hurdle.
Having some basic issues getting started here. Not totally sure where I am going wrong.
Trying to use https://github.com/aacotroneo/laravel-saml2; Running Laravel 5.4 on a development WAMPserver; installed the package fine, added provider and alias information to config/app.php as per all instructions.
If I try to publish the config file, I get no action, no error, just "Publishing Complete" in Composer.
I can copy the saml2_settings.php file to the config directory from the provider directory, and set the parameters there instead, however, no routes work - trying to get the metadata via /saml2/metadata URL just gives me a 404.
Any ideas - new to SAML but this seems just like a standard installation issue.

1) You need to add SAML2_IDP_HOST in env
2) Your url must contan prefix 'routesPrefix' => '/saml2', so your routes looks like below,
/**
* If 'useRoutes' is set to true, the package defines five new routes:
*
* Method | URI | Name
* -------|--------------------------|------------------
* POST | {routesPrefix}/acs | saml_acs
* GET | {routesPrefix}/login | saml_login
* GET | {routesPrefix}/logout | saml_logout
* GET | {routesPrefix}/metadata | saml_metadata
* GET | {routesPrefix}/sls | saml_sls
*/

Related

Cahephp 3.x : dashed rest api not working

I'm building a RESTful API System with CakePHP 3.1.13 ( i can't use 3.2.x because the Server PHP Version is 5.5.x ).
My controller name is CmsCouplesController.php and the url :
http://localhost/~emanuele/works/grai/html/api/v1/cms-couples.json
works correctly.
BUT the other call ( http://localhost/~emanuele/works/grai/html/api/v1/cms-couples/1.json ) return :
Action CmsCouplesController::1() could not be found, or is not accessible.
If i create a controller CouplesController.php all works fine.
So why?!
UPDATE : routes configuration
Router::scope('/', function ($routes) {
$routes->prefix('v1',function($routes) {
$routes->extensions(['json','xml']);
$routes->resources('Couples');
$routes->fallbacks('DashedRoute');
});
Resource routes require separate inflection configuration
You are missing the proper inflection configuration for your resource routes. By default resource routes are using underscore inflection, ie currently your resource routes will match cms_couples.
Note that you can easily check which/how routes are connected by using the routes shell
bin/cake routes
It will show you something like
| v1:cmscouples:index | /v1/cms_couples | {"controller":"CmsCouples","action":"index","_method":"GET","prefix":"v1","plugin":null} |
| v1:cmscouples:add | /v1/cms_couples | {"controller":"CmsCouples","action":"add","_method":"POST","prefix":"v1","plugin":null} |
| v1:cmscouples:view | /v1/cms_couples/:id | {"controller":"CmsCouples","action":"view","_method":"GET","prefix":"v1","plugin":null} |
| v1:cmscouples:edit | /v1/cms_couples/:id | {"controller":"CmsCouples","action":"edit","_method":["PUT","PATCH"],"prefix":"v1","plugin":null} |
| v1:cmscouples:delete | /v1/cms_couples/:id | {"controller":"CmsCouples","action":"delete","_method":"DELETE","prefix":"v1","plugin":null} |
Long story short, use dasherize inflection and you should be good.
$routes->resources('CmsCouples', [
'inflect' => 'dasherize'
]);
See also
Cookbook > Shells, Tasks & Console Tools > Routes Shell
Cookbook > Routing > URL Inflection for Resource Routes
API > \Cake\Routing\RouteBuilder::resources()
from my understanding...
http://localhost/~emanuele/works/grai/html/api/v1/cms-couples.json
must be pointing to index function of CmsCouplesController.php controller
then for what reason you want this kind of url
http://localhost/~emanuele/works/grai/html/api/v1/cms-couples/1.json
you can give url like
http://localhost/~emanuele/works/grai/html/api/v1/cms-couples/json-request
then you can put your code in jsonReuest function of the CmsCouplesController.php controller ...
If this does not help then explain your question with answer of my question of why you want URl like 1.json

NotFoundHttpException when editing an object

I have tournament > category > setting, and I need to edit the settings.
For the creation ( http://laravel.dev:8000/tournaments/1/categories/5/settings/create
) , I have no problem, only updating is failing ( http://laravel.dev:8000/tournaments/1/categories/2/settings/5/edit )
I checked the params (1,2,5), and they are OK.
I use my route with resource()
Route::resource('tournaments/{tournamentId}/categories/{categoryId}/settings', 'CategorySettingsController');
When I type php artisan route:list, I get this route:
GET|HEAD | tournaments/{tournamentId}/categories/{categoryId}/settings/{settings}/edit | tournaments.{tournamentId}.categories.{categoryId}.settings.edit | App\Http\Controllers\CategorySettingsController#edit | auth,roles |
So, as for me, everything should be OK, I don't understand why I get a NotFoundHttpException
Any idea????
in RouteServiceProvider.php, I had binding defined:
$router->model('settings','App\Settings');
So General settings bindings was conflicting with Category Settings

How do i get my resource controller to fire the destroy _method?

I am having a problem with the laravel5 resource controller. The POST method is working fine however the delete method is not. as you can see from postman i am passing the DELETE _method to the correct route
In the mean time i am using direct routes which are also working fine.
Route::delete('customisemymeal', ['as'=>'customisemymeal', 'uses'=>'UserMealCustomController#destroy']);
Route::post('customisemymeal', ['as'=>'customisemymeal', 'uses'=>'UserMealCustomController#store']);
I have disabled the CSRF token check until this is sorted out.
Can you please help explain why the same method is different for a resource controller compared to a route::delete?
routes:list
| DELETE | customisemymeal/{customisemymeal} | customisemymeal.destroy | App\Http\Controllers\UserMealCustomController#destroy |
| DELETE | customisemymeal | customisemymeal | App\Http\Controllers\UserMealCustomController#destroy |
To use the route:
Route::resource('customisemymeal', ['as'=>'customisemymeal', 'uses'=>'UserMealCustomController']);
You must abide to a few rules. To delete something you need to use:
domain.com/customisemymeal/resource_id
From your screenshots you are trying to delete a resource, using a different URI.
domain.com/customisemymeal
That won't work.
Rules are:
Index:
GET -> domain.com/resource
Show:
GET -> domain.com/resource/resource_id
create:
GET -> domain.com/resource/create
edit:
GET -> domain.com/resource/resource_id/edit
update:
PATCH / UPDATE -> domain.com/resource/resource_id
store:
POST -> domain.com/resource
delete:
DELETE -> domain.com/resource/resource_id

Laravel 5 cannot call DB::table() directly outside a class

In my public/index.php of a Laravel 5 application, I have to query some fields in my database, so I used DB::talbe() to do that.
But it returns error:
Fatal error: Class 'DB' not found in C:\xampp\htdocs\oceanboost\public\index.php on line 49
The code I used to call is:
$_active_plugins = DB::table("option")->where("key", "_active_plugins")->first();
I tried to use
$_active_plugins = \DB::table("option")->where("key", "_active_plugins")->first();
but the same error
And here is my full code of public/index.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylorotwell#gmail.com>
*/
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/
require __DIR__.'/../bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$_active_plugins = DB::table("option")->where("key", "_active_plugins")->first();
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
My question is how to call built-in classes like DB in a file when this file is not a class
It's not possible to use the DB facade at that point. The whole database component is booted from the Kernel at this part:
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
Before that it's not available.
What you should do, is create a Service Provider for that. I won't go into all the details but you basically add a class that has a register and an optional boot method. You can create one with an artisan command:
php artisan make:provider PluginServiceProvider
In there you can use the DB facade like you want to. Then you just need to register that provider in config/app.php by adding it to the long providers array and your code will run before any routing or such happens.
Note that you should put your code into the boot method since this one is called after all other providers have been registered.
#Nguyen, if I am not mistaking, I think you are trying to query the database in the public/index.php, which is a very big mistake when considering MVC Frameworks.
Please to do this, you should query your database in a controller then pass the results to a view which will be returned to the index.php.
And if you are in a dilemma, see laravel docs

How do I display information from a form?

I am trying to display information submitted from a form to create a message board. I am using php in the laravel framework. I am using a form, record, and repository. Whenever I try to display the content I receive the following error Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException.
Here is the controller:
/**
* Display a listing of the resource.
* GET /messages
*
* #return Response
*/
public function create()
{
return View::make('comments.create');
}
public function show($comment)
{
$message_id = $this->messageRepository->find($comment);
return View::make('comments.show')->with('comment', $message_id);
}
/**
* Store a newly created resource in storage.
* POST /messaages
*
* #return Response
*/
public function store()
{
$data = Input::all() ;
$this->messageForm->validate($data);
$messageRecord = new MessageRecord;
$messageRecord->comment = $data['comment'];
Return "Comment created";
}
}
Here is the view causing the trouble:
<p>$comment</p>
I have not been using a route but I threw this together:
Route::resource('/message', 'MessageController');
[Edit:]
If your store() is already used by another form and you still have another form to send POST data then, you should declare another routes for that. Like
Route::post('message/display', ['as' => 'message.display', 'uses' => 'MessageController#display');
Sorry for my previous answer, show() is for GET request and since you are using form you probably you don't need it unless you decide to send data through url. I'm extremely sorry.
[Edit ends]
You are getting that error because you are not allowed to use display() in resourceful routing. Instead, you must use store(). Since you are using laravel resourceful routing, you should follow the convention of laravel. In your command line, run
php artisan routes
You will get something like this,
GET|HEAD message | message.index | MessageController#index
GET|HEAD message/create | message.create | MessageController#create
POST message | message.store | MessageController#store
GET|HEAD message/{message} | message.show | MessageController#show
GET|HEAD message/{message}/edit | message.edit | MessageController#edit
PUT message/{message} | message.update | MessageController#update
PATCH message/{message} | | MessageController#update
DELETE message/{message} | message.destroy | MessageController#destroy
These are the methods, their route names and their corresponding HTTP request that you should use.
Check Laravel documentation for resourceful controller
For quick look,
index : Display a listing of the resource,
create : Show the form for creating a new resource,
store : Store a newly created resource in storage,
show : Display the specified resource,
edit : Show the form for editing the specified resource,
update : Update the specified resource in storage,
destroy : Remove the specified resource from storage
It seems you use incorrect verb for route displaying this route. For display you should probably use Route::get and you probably use Route::post. If it's not the issue you edit your question and put there routes.php as you were asked in comment.

Categories