简体   繁体   中英

How to use session authentication in ember.js http requests?

I'm developing a web (frontend in ember.js - but I'm a newbie) using session authentication in the backend.

I have a bit poor knowledge about sessions and CSRF so I'm basically asking what should I implement this request

this.store.createRecord('entity', {'text': 'blabla'}).save();

or what else have to be done, so the request can pass through session authentication in the backend. So far it just returns error 401, non-authorised access.

so basically you might be required to add headers of session ids in your rest requests of Ember Data. To make sure all ember data rest requests have those headers you can add them in application level like below

App.ApplicationAdapter = DS.RESTAdapter.extend({
  headers: {
    "API_KEY": "secret key",
    "ANOTHER_HEADER": "Some header value"
  }
});

As you mentioned in comments, in your case you needed to add X-CSRFToken in your headers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM