Flutter does not return “set-cookie” header from basic auth in chrome/web

时光毁灭记忆、已成空白 提交于 2020-11-30 01:41:09

问题


I have this flutter basic auth method that works fine in mobile, returning the expected response/headers/cookie upon a 200 status code -->

{set-cookie: JSESSIONID=859C68D3047BFBE5CD779D172C8F7422; Path=/; HttpOnly, cache-control: no-cache, no-store, max-age=0, must-revalidate, date: Thu, 05 Nov 2020 04:16:03 GMT, vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, content-length: 5, content-type: text/plain;charset=UTF-8, x-frame-options: DENY, pragma: no-cache, x-xss-protection: 1; mode=block, x-content-type-options: nosniff, expires: 0}

For some reason when I run the same code on flutter chrome, getting a 200 response returns a different/incorrect response/headers/cookie -->

{cache-control: no-cache, no-store, max-age=0, must-revalidate, content-length: 5, content-type: text/plain;charset=UTF-8, expires: 0, pragma: no-cache}

This is what my sign in auth method looks like addl:

signIn(String email, pass) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();

    String basicAuth =
        'Basic ' + base64Encode(utf8.encode('$email:$pass'));

    var r = await http.get('http://localhost:5000/',
        headers: <String, String>{'authorization': basicAuth});


    var jsonResponse = null;
    if(r.statusCode == 200) {
      jsonResponse = r.headers;
      if(jsonResponse != null) {
        setState(() {
          _isLoading = false;
        });
        print(jsonResponse.toString());
        print(jsonResponse['set-cookie'].toString());
        sharedPreferences.setString("JSESSIONID", jsonResponse['set-cookie']);
        print(sharedPreferences.get("JSESSIONID"));
        Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (BuildContext context) => MainPage()), (Route<dynamic> route) => false);
      }
    }
    else {
      _showMyDialog("Invalid Credntials","The username/password combination does not match our records");


    }
  }

when I check in the browser console its identical to that of the mobile response, returning the correct response/headers/cookie. Why is flutter returning this incorrect response? How can I get the "set-cookie" piece to return?.....I have referenced Can't Access Cookie in HTTP Response with Flutter already and not had any luck.

来源:https://stackoverflow.com/questions/64691179/flutter-does-not-return-set-cookie-header-from-basic-auth-in-chrome-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!