Skip to content

New and Fresh Private + Public Proxies Lists Everyday!

Get and Download New Proxies from NewProxyLists.com

8 – Decoupled login: How to get drupal’s session cookie via Javascript?

I have an Ionic React app, and I want to use Drupal’s session cookie, not Oauth or JWT.

Desired flow

  1. User logs in inside the Ionic app.
  2. User does stuff inside the app.
  3. User sometimes clicks a link to my Drupal site and is still logged in to the site because I am using a Drupal session token.

I have been using OAuth, but the problem with OAuth is that if I click a link to a page on my Drupal site (outside my app), then I am not logged in on that page.

In my case, I really need to be able to easily redirect from inside my app to the Drupal site and stay logged in, so I want to use the Drupal session cookie for this.

Where I’m stuck is how do I get the session cookie from Drupal using Javascript?

The jsonapi documentation gives this example:

`curl --header "Content-Type: application/json" -c cookie.txt 
--request POST "http://example.com/user/login?_format=json" 
--data '{"mail": "test@example.com", "pass":"password"}'`

However, I only have access to Javascript, not curl, in React. Also, I’m thinking that I may be over-thinking this and there is a really simple way to get the session cookie that I have overlooked.

So, how do I get the login session cookie via Javascript?

Background

I understand that the best practice is “use OAuth 2 or JWT; they are more secure.”

In fact, the Simple Oauth module has good documentation and I managed to set this up on my site using the Drupalize.me react tutorial.

Author AdminPosted on February 18, 2021Tags cookie, decoupled, drupals, Javascript, login, session

Post navigation

Previous Previous post: oa.operator algebras – Is there a finite depth irreducible subfactor of prime index and not group-subgroup?
Next Next post: VSCode GitHub Error – Stack Overflow en espaƱol
New and Fresh Private + Public Proxies Lists Everyday! Proudly powered by WordPress

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123