How to authenticate Drupal users in an external Laravel php application - php

I'm looking for a way to build a php application (in Laravel) that reuses the existing users we have in a Drupal installation.
I found two suggested solutions on stackoverflow:
1) include the Drupal bootstrap and use their user_authenticate() method.
One thing I suppose will be a problem is that our PHP application is running on a different server. This approach will probably not work in such a case or can that be fixed by pointing to the Drupal sql server?
2) use the Drupal services module to authenticate users over REST
This might work over different servers/domains I suppose, but there won't be a way to automatically login users in our php app that are already logged into Drupal, or am I wrong.
3) synchronise the Drupal user data to our own SQL server
This would be a final resort, since this won't solve automatic login.
Are my thought correct in these situations. What would you suggest doing when Drupal and the PHP app are on two completely different servers/domains?

I ended up writing a custom provider in Laravel.
If you're interested in doing the same thing, here's what I did: Create a custom Drupal 7 authentication driver/provider in Laravel 4

Related

How to add OAuth2 Server on a CakePHP 3 plugin

I am working on a plugin in CakePHP3 and I need to create a simply Oauth 2.0 Server API that allows to do a simple CRUD on the users' table and create sessions when needed.
I have done some research here in StackOverflow and it seems that the best choice would be
https://github.com/uafrica/oauth-server
Now, I have tried to make it work according to the doc in the repository but since it will be a plugin, not the core of the application I do not understand how it is supposed to work and which file I need to update.
Would somebody be so kind to give me the list of steps I need to follow and the actual files that need to be updated?
Many Thanks in advance
The uafrica/oauth-server project is woefully out of date. It requires v4.1 of league/oauth2-server, which is now currently at v7.2. Version 5 of that project was completely rewritten and is not backwards compatible with v4.x.
I don't think there's an out-of-the-box CakePHP 3 plugin that works with the current version of league/oauth2-server.
You'll have to either build your own plugin from scratch, or try to hack the uafrica/oauth-server project to get it work with league/oauth2-server.

Laravel Passport for Authenticating Multiple Installations

I'm looking to recreate some internal systems using Laravel 5.3 as the internal systems need rebuilding. I am still fairly new to Laravel as we have used a bespoke framework based on PHP 4 for a few years, which is starting to show its' age.
The current setup makes use of having a users table for each application, which from my knowledge is not efficient as the userbase is shared (open to all employees).
Would I be right in thinking that I can set up a Lumen application, with a database of users, and then use Laravel Passport to make it an OAuth2 server? Say for example, passport.company.com and then new users are registered via this application.
Therefore, another two applications using Laravel i.e. CRM and CMS can then use the Passport system for authentication, rather than having to create users tables for each application?
If this is on the right lines, or there are better alternatives, I would be grateful to hear your feedback.
Thanks!
Edit: It appears that I'd need Laravel for all applications and not Lumen, after reading further into it.
I'm still curious as to know if I am on the right track however?

How can I use both Laravel and Drupal in my website?

I have a website build in Drupal 7. Due to complexity of some pages I want to build those pages in framework like Laravel!
Can I do that?
I want to keep user login and some node functionality of Drupal and will use Drupal's db!
You can but you shouldn't. The Drupal and Laravel are both back-end frameworks. By keeping some part of Drupal and another from Laravel will create problems for you later if not now. Just for example, you will have to sync session management of both systems to keep things synced!
Rather, I would suggest you go for some Front-End frameworks like BackBone, Angular etc. It'll effectively work with Drupal, as Drupal provides the REST API support.

Share session between two systems in Zend Framework v1

I'm facing an issue that's beyond my Zend Framework knowledge, i hope you guys could help.
I have a old fully-functional system installed in my server (let's call it http://stable.server.com), which has a very old PHP version. I'm planning to upgrade my PHP version to the latest (and hopefully in a few months, to 7!) but my code uses a lot of deprecated functions and has some code that isn't valid for PHP 5.6 but it was for older versions. I've made a division of modules in order to migrate each module, test it and then upload it to a parallel server with the latest PHP version (let's call it http://updated.server.com). Of course each one has a different Zend installation, with the same version and configuration file.
Of course those modules has some communication between themselves, and I want to keep the change the most transparent for my users. So when I call from updated.server.com to stable.server.com and viceversa, my app asks me to login again. When I'm logged in the two systems, this communication goes straight, but I want to avoid the users to login again.
¿Any of you have made something like this? I'd like of course a secure way to avoid that login between systems, so nobody could mount a fake system and login from it.
Thank you all in advance.
I think you are looking at the two different problem.
Session is written on disk this information needs to be shared between two servers.
Cookie needs to be persistent through out the domain/subdomain.
for session sharing you can use mysql session storage.
http://framework.zend.com/manual/1.12/en/zend.session.savehandler.dbtable.html
http://framework.zend.com/manual/1.12/en/learning.multiuser.sessions.html
https://github.com/sprain/PHP-MySQL-Session-Handler/blob/master/MySqlSessionHandler.php
you can google it there are so many solution out there.
2.Domain set cookie for subdomain
you can set your cookie to be ".server.com" then it will live through out of your all domains.
This is not simple fix!! but once you are done with this implementation you can run both version at the same time on different machine with same session information.

View and controllers on different machines in Laravel

I have got a requirement from a customer that my web UI should not have any direct access to my database. My web app is built in php using the Laravel framework and Eloquent. One option is rewriting the code in my controller and model into a webservice (in any other language be it php or java) and calling the webservice from the UI, but this will involve tremendous work. Is there any way in Laravel where I can move my controller and model to another server and calling the controller from UI via Laravel routes? The view must be on one machine and the model-controller on another machine.
To the best of my knowledge this cannot work. Although Laravel is highly customisable, the work involved in moving your entire application to a new server while keeping the view where they are is extremely too much and possibly won't work.
Your suggestion to use web services is something to consider but in reality you will be creating a static website in one server which uses API's to talk to Laravel on a other servers. They will not be views and definitely not in blade templates. Remember that you have other UI related dependencies in vendor and public directories.
My suggestion is to have the DB on a separate server which you can connect to by editing the config files - this is a very normal setup.
Then if you want you can create some web pages which use the API to talk to Laravel from another server but again I cannot see why this would be needed as the views are still not accessible by anyone other than the server.
Please let me know if I'm missing something :)

Categories