Score:1

How can I use a JWT from a headless front end to automatically log in a user on a different subdomain?

cn flag

I've got a headless application with a vuejs frontend on mysite.com and a Drupal backend on backend.mysite.com, so that users can still leverage Drupal's forms, etc.

Of course, backend.mysite.com/user/login works out of the box, and I have login working on the frontend via https://www.drupal.org/project/simple_oauth (which generates a JWT for access/refresh tokens). The issue is that there is no relationship between being logged in on the frontend and being logged in on the backend.

Is there a recommended way to have an "automated SSO" of sorts that leverages the tokens that have already been generated to log the user into the backend? I guess what I'm thinking is that I would present the user with a button/link on the frontend that sends them to backend.mysite.com while handling the authentication automatically, but I'm not sure what to do logistically to make that happen.

cn flag
I may not understand your question, but if there is a drupal backend on a subdomain, and then on the main/bare domain you have VueJS with login via Drupal's Simple OAuth, are there two drupal installations (Drupal A powering VueJS login and Drupal B powering the subdomain)?
cn flag
No, there’s a single installation. The subdomain is the full drupal installation. The vuejs login essentially just gets an authentication token from the backend that can be used for API requests. The vue app is really just an API consumer.
cn flag
To be more clear, the vuejs login is just a standard <form> that POSTs to an endpoint on the drupal backend, but it doesn’t initialize a drupal session like happens when you log into drupal regularly.
cn flag
I see. I have an Ionic React webapp/mobile app with a full drupal site as well, but I set it up by hosting the full Drupal site at the domain, and then putting the mobile app files in a subdirectory (www.example.com/myapp) and serving the mobile app files directly from nginx. In this case, when a user logs in to the React webapp, they also get a Drupal cookie since it's on the same domain.
cn flag
Ah gotcha, makes sense. Yes just a different setup.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.