Flutter web Traccar set-cookies

Zubi139 months ago

Hello!

I have have a flutter app connected to my custom hosted traccar server, everything works in mobile app side (reading cookies).
And in same project flutter web is also enabled. and same everything else works fine in web except reading set-cookies (I need cookies for web socket connection)

The problem is that in flutter web I can not access the set-cookie. sometimes its there in web console but in flutter side i can not get the value. i have done many configuration changes in server side, cros origin or sameSite configurations.

just to point that the website is hosted in firebase hosting and https and ssl is already enabled in server side.

Still not sure if its browser issue or just flutter web issue or server configuration.

And Anton, isn't there any other way to connect with web socket other than giving the session id cookie ?

Thanks in advance.

Anton Tananaev9 months ago

You won't be able to access cross-origin cookies. The best option is to proxy everything, so it's on the same host.

Zubi139 months ago

Thank you for the response.

So how about hosting the website in the same host as the server will that help ?

Anton Tananaev9 months ago

It won't be a cross-origin, so you don't need to worry about cookie restrictions.

Zubi139 months ago

Ok thank you, I will try these solutions.

Zubi139 months ago

Apparently the file etc/apache2/sites-available/traccar.conf . which is configured for secure connection

already contains

              ProxyPass /api/socket ws://localhost:8082/api/socket
               ProxyPassReverse /api/socket ws://localhost:8082/api/socket

               ProxyPass / http://localhost:8082/
               ProxyPassReverse / http://localhost:8082/ 

Is this enough or we need modify accordingly ?

Anton Tananaev9 months ago

Is you app also proxied there?

Zubi139 months ago

The is making api requests to with base url https://prtadmin.xyz/api/session

Anton Tananaev9 months ago

I don't think you answered my question. Maybe you didn't understood my original point? Your app and API have to be on the same host.

Zubi139 months ago

Hi, sorry ignore the previous message.

So currently the web app is hosted still in firebase, firstly if possible I want to try to solve the issue without having to shift webapp to same host as server.
as you suggested I checked proxies. as you see the default proxy is already there.
the web app domain is prtgps.com as of now, and apis endpoint is https://prtadmin.xyz/api (this is the server domain name)

And in flutter web or any web you can not make proxy request as per my searches now.
so its a normal api request to for example "https://prtadmin.xyz/api/session".

So please tell me if i need to modify the proxy values in server or default ones are correct?
And if you think the only way is to shift the webapp in same host as apis then I shall do that.

Anton Tananaev9 months ago

You don't have to shift the hosting. You can just proxy it. That's what I said originally.

Zubi139 months ago

Yes correct,

So now my question is that what should i replace instead of http://localhost:8082/ according to info i gave in previous response.

 ProxyPass /api/socket ws://localhost:8082/api/socket
 ProxyPassReverse /api/socket ws://localhost:8082/api/socket

               ProxyPass / http://localhost:8082/
               ProxyPassReverse / http://localhost:8082/ 
Anton Tananaev9 months ago

I cannot give you exact steps by step details. I'm just pointing the general direction.

Zubi139 months ago

Thank you, anyway I got a workaround for now.

Zubi139 months ago

Hi Anton,

A quick question , now I get sessionId cookie.

can we connect to websocket with any of the following too ?

1. wsUrl = wss://prtadmin.xyz/api/socket?token=(generated token from session/token)
2. wsUrl = wss://prtadmin.xyz/api/socket?session=(sessionId from the cookie)

channel = HtmlWebSocketChannel.connect(
           wsUrl
      );

In flutter mobile app i can easily and successfully connect to websocket by below method. but in web we can't pass headers like this.

wsUrl =  wss://prtadmin.xyz/api/socket
channel = IOWebSocketChannel.connect(
              wsUrl,
              headers: {'Cookie': Constants.currentSessionID!}
          );