Using SimpleSAML with Yii2 - Multiple Autoload Issue - php

As the title suggests, i've currently got a working Yii2 portal, which we're upgrading to enable use of SSO with SAML.
For handling the authentication we're using SimpleSAML, which is sat outside of the web root as the SimpleSAML documentation instructs.
The problem being, both Yii2 and SimpleSAML have their own instance of composer, along with its own autoloader. So i'm having problems finding a way to successfully require the SimpleSAML composer autoloader from within Yii2, which is already requiring it's own composer autoloader.
Can anyone offer any guidance on this?

I managed to solve it, rather than a problem with the require, it was a problem with calling the function the correct way in Yii2, so using the example on the SimpleSAML website, within Yii2 add a slash to whichever function you need to use, as so:
$as = new \SimpleSAML_Auth_Simple('default-sp');

You will need to fix the conflict issue patching the autoloaders.
I recommend you to read:
http://alanstorm.com/laravel_composer_autoloading
https://github.com/composer/composer/issues/3003
http://www.yiiframework.com/doc/guide/1.1/en/extension.integration
Or take a look on this easy php saml toolkit: https://github.com/onelogin/php-saml

Related

Adding auth to existing project with Laravel Alpine and Livewire

I have an existing laravel project with AlpineJS. I wanted to integrate authentication but not able to find a proper solution having in mind I DONT USE VUE. I have done this with Vue but just wanted to know if there's an updated guide for Laravel with Alpine JS. I tried to look into documentation but wasnt able to find something related.
composer require laravel/ui
php artisan ui:auth
Do I still need to do this? Any suggestions for best practices?
Alpine is just a lightweight framework for DOM manipulation, it's not going to provide any authentication functionality alone so you will need to add something to your project.
If you're wanting to add authentication to your application, you'll want to consider something like Laravel Fortify which is a headless front end agnostic authentication solution. There are starter kits such as Breeze or Jetstream, however, adding either of these boilerplate start kits to existing projects can have issues. Some people recommend starting a new project, installing one of them and them porting your existing functionality across (this will obviously depend on the scale of your project).

Laravel - share functionality between multiple separate codebases

So I have a project here that consists of several websites, and rather than writing functionality such as a login flow and signup flow into each project codebase I’m looking for a way to write these shared components once and include them as dependencies into all of the required codebases.
The login flow, for example, consists of:
model,
view
controller
repository
JavaScript
css
unit tests
database migrations
all other code related to the login flow
I would really like to be able to just include these shared functionalities via composer for example. Is there a way to do this?
Docker community edition, Laradock, Laravel 5.7, PHP 7.2, composer.
if you need to Share function you can make this function in helper function then put path in autoload path this link will help you for more understand

How can I use a third party api in the vendors directory of symfony from my controller

I am working with an existing controller in symfony and need to use an api that I have in my vendors directory. Needless to say I am entering a pre-existent, large scale project and with minimum experience in symfony I am not too sure of how to use the vendor directory. When I have tried using "use vendor\fullcontact\sdk*********;" symfony tells me that there is no class called this in my bundle. I have looked for information on using the vendor directory but have came up dry. Any information regarding how I can start using my vendor directory would be appreciated.
Seems you are using the PHP Library for FullContact API.
This library don't use namespace so you can simply try to use it adding an initial slash to the class when you are using it. As Example:
$this->name = new \Services_FullContact_Name($apikey);
Hope this help

How to install simpleSAMLphp framework with Zend framework 1

I am working on an application that was built in Zend framework 1. I want to install simpleSAMLphp as a service provider for it and trying to figure how best to do this.
I'm considering a couple of options:
Install it outside the application
(e.g. /var/www/myapp/simplesamlphp where my app's files are at /var/www/myapp/simplesamlphp). This is how it seems it's done in the installation tutorials. I guess this would work with some adjustments to the autoloading so it can pickup the SimpleSamlphp classes. I'm using composer to install dependencies so I can perhaps add the SimpleSAML folder to the class tree - not tried this yet. Or should I use the SimpleSAMLphp autoload file?
simplesamlphp-composer
I sees there is an option install with composer? So, if so, it will go within my application folder and files. However, I've tried this and not sure how to get composer to pick up the SimpleSAML classes. Anyone had much use of this method? I tried doing composer dump-autoload but it didn't add them. I guess I need to do more.
Can anyone give me some advice on how to use simpleSAMLphp with ZF1. Even just a point in the correct direction regarding where best to put files. We want to role this installation out to all our websites eventually so something that is easy to setup would be best I guess. I do like the composer approach but didn't have much luck with it. Previously the project used CAS with a phpCAS client - that was installed using composer which was quite convenient.
Any help would be much appreciated, thanks
I used ZF 1 and had following structure
/lib/Zend/ -- ZF
/lib/Zend.php
/lib/MyCompany/ -- my classes that supports ZF autolaod
/lib/ANyOtherZFCompatible
/lib/external/ -- any other libs that don't support ZF convention
I would put SimpleSAML into /lib/external/simpleSAML/
and at the beginning of your main file
require_once('/lib/external/simpleSAML/lib/_autoload.php'); and try to use init some SAML classes.

How to include external library in Zend Framework 2?

I played with the zf2-tutorial successfully, but I was totally confused when trying to integrate an external library like "jpgraph". I know I must do this with autoload or servicemanager but it won't work.
The php-files of jpgraph are in the vendor/graph directory. I use a module called Jpgraph, in the controller indexAction I try:
$graph = new Graph($width,$height);
this gives me an error:
Fatal error: Class 'Jpgraph\Controller\Graph' not found in ...
the jpgraph library don't use namespaces.
i also tried this way without success
what's the best way to integrate such things?
I would be glad for every tip or help
Add the library to your composer.json and add the class with Classmap and/or the include path as phpunit does
https://github.com/sebastianbergmann/phpunit/blob/master/composer.json#L48
One option, as Maks3w pointed out, is to use Composer. If you've never heard of or used composer before it's definitely worth a look. I was surprised how easy it was to set up and use 3rd party libraries. It's also very easy to set up your own library to work with composer, and use any source controlled (git or svn) library of your own - works well with GitHub repos - just add a composer.json file.
On the other hand, you do not need to use composer to do what you want, it would make it very easy, but it may be overkill. Zend Framework 2 has a very flexible autoloader system, and although it works well with PSR-0, you can have any class autoloading sytem that you like. Take a look at the different components of Zend\Loader, in particular I think the ClassMapAutoloader will be the one to suit your needs.

Categories