Need Help With X-CSRF-Token issue ! :(


#1

I have a backend with drupal !

Using Drupal Services to interact with. which provides a rest server !
Created endpoint named ‘api’

Following sequence works in normal browser or any http client like postman :-

  • example.com/api/login (works)
  • api sends back user data (token,session id, session name etc).
  • Further any request i make , i send token as X-CSRF-Token (all requests work).
  • i can even logout the same session with the token received before !

IN IONIC APP :-

I can login and i am also able to store user data (token, session data etc). in localstorage after login

here’s the difference in app :-

When i send same token back to server while making a request ( say logout)

Server’s Response is “User is not Logged In.”

Why does this happen ?

PLEASE HELP !
Help is appreciated !


Ionic + Drupal series
How to implement a cookie-based authentification
#2

Update :-

After logging in i tried getting the current token from the server , and it was different from the one i saved after successfully logging in !

every time different token is received ! Some one help with this authentication issue … :pensive:


#3

Hi @Sumeet123!

Its because you forgot to set the session data in your cookie :slightly_smiling:

Also hav painful days with this. :smiley: (btm postman / chrome in general sets the coocies automatically :wink: )

Because handling drupaly API is not the easyest thin i created a angular repo to handle a lot of requests. I also created a authentication service which makes your suth flow a copy paste thing. :slightly_smiling:

check it out! => ng-drupal-7-services

I also created an IONIC DRUPAL DEMO


#4

@BioPhoton Thats great ! :heart_eyes:

cant wait to try :stuck_out_tongue: after giving up wih that session auth i cosidered basic auth which anyhow was going to work !

I am surely trying that ! thanks for the help and appreciate :slight_smile: