Hi people,

I am building an application on Drupal but due to some Drupal constraints and module customize limitation some features I need to build on Laravel framework. Drupal will be deployed on "example.com" and Laravel will be deployed on "subdomain.example.com" on the same server.

User authentication will be done through Drupal, so user session management will be maintained by Drupal. Now the twist is as I said some features will be developed on Laravel framework. Let's take an example to make it more clear.

Application flow

  1. User Logs in through Drupal
  2. There will be menu items for eg. A, B, C, D. Now A & B menu items have href link to example.com/a & example.com/b respectively but c & d have href link to subdomain.example.com/c & subdomain.example.com/d where C & d menu logic is built on Laravel application so when user click on c or d s/he will be redirected to Laravel application.
  3. Now my question is when navigating from Drupal to Laravel I need to authenticate the user on Laravel side also and once authentication is done on Laravel side new session for that user will be maintained on Laravel application.
    Drupal will have its own session and Laravel will have its own session for the same user. How can we achieve this??
  4. I have one solution but is it the correct way to do?? If not then the best way to do this?

Solution:

  1. I will be using JWT(JSON Web Token) to interact will Laravel application.
  2. for eg when user logs into Drupal JWT token will be generated and when the user navigates to Laravel application JWT token will be authenticated to check user's identity on Laravel side and if it's valid then the session will be maintained on Laravel. I will be using the same database for Drupal and Laravel

Comments

miguelrock222’s picture

Hi! First of all, Sorry for my english.
actually i have the same situation, need to be able to authenticate a user in both applications, i'm using Drupal 8 and laravel 5.5, and i was thining in that way, i'm searching and foud this post, can you tell us if that works, i will try in next days and share the way that i make that.
Thanks a lot!

DeeMoney’s picture

Hi guys, its been a while since this post was created. I found it while searching for a solution to link Drupal and laravel, so that drupal and laravel can share nodes. Any updates on this? Thanks for the feedback