Cors issues with angular dart – cookies not set


I work on a app using angular.dart at the clientside and dart in the serverside.
I have write a login rest entrypoint and want to set cookies the header was in the response but the cookies are not set.

set-cookie:app-user=533c1470a2658184a7625d7d; Expires=Tue, 8 Apr 2014 9:15:47 GMT;; Path=/
set-cookie:app-tokn=530fa71b615e168787a7cb5b5c589a5601065e1e3f921d4b770c784394de3a42; Expires=Tue, 8 Apr 2014 9:15:47 GMT;; Path=/

I try to check my headers or my value set in cookies, but to my mind is good

headers :

                ..headers.set(HttpHeaders.CONTENT_TYPE, 'text/plain: charset=UTF-8')
                ..headers.add("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE")
                ..headers.add("Access-Control-Allow-Headers", "origin, x-requested-with, content-type, accept")
                ..headers.add("Access-Control-Allow-Origin", "*");

cookies :

static setCookie(HttpRequest request, String key, String value, DateTime duration) => 
  request.response.cookies.add(new Cookie(key, value)..path  = '/'
                                                  ..expires  = duration
                                                  ..domain   = '');

I follow some threads on stackoverflow and google groups and I think it’s a problem of “withCredientals” a value I have set in an another projet (angular/Java) but I don’t find this parameter on angular.dart.

Can you help me to find it or have you somes ideas?

Thank you for your help/time


I’m not sure if I understand you question correctly but maybe this is what you are looking for:

(on the client)

  var request = new HttpRequest()"POST", uri.toString(), async: true)
    ..withCredentials = true // seems to be necessary so that cookies are sent

I missed that this is about Angular. This needs a slightly different approach.

If you use the Angular http service you have a parameter

class MyController {
  Http _http;
  MyController(this._http) {
    _http.getString('someurl', withCredentials: true).then((e) => ...);
    // or _http.request('someurl', method: 'POST', withCredentials: true).then((e) => ...);

Answered By – Günter Zöchbauer

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *