Code Monkey home page Code Monkey logo

Comments (9)

olofd avatar olofd commented on June 27, 2024 1

Ah. interesting. Of course I have not used this lib with credentials, so there we have our discrepancies. Let me look into this tonight and I'll get back to you.

from react-native-signalr.

olofd avatar olofd commented on June 27, 2024

Hmm.. weird. And I guess it's not the same as #11 ? Must be something wrong in the setup/rn-version or something. Hard to guess without repro. Websockets works in iOS on my end of course. Can you somehow debug on the server and see if the connection is received?

from react-native-signalr.

olofd avatar olofd commented on June 27, 2024

@somoso Did you have any success in tracking down this issue? Let me know if I can help in any way. But I will need more info/better debug-scenario to be able to help efficiently.

Will close in a couple of days if I do not hear from you.

from react-native-signalr.

somoso avatar somoso commented on June 27, 2024

Thanks for checking this out - I'll give #11 a go and if that fails, I'll see if I can have access to the actual server and debug it from there.

from react-native-signalr.

somoso avatar somoso commented on June 27, 2024

Just a quick update, I've added NSAllowsArbitraryLoads in my Info.plists file and I couldn't get it to behave. For now I'm going to close this issue, but I'll reopen if I have any questions or issues with react-native-signalr.

Thanks for the help though!

from react-native-signalr.

somoso avatar somoso commented on June 27, 2024

OK, so I've managed to understand what is going on with a little help with Wireshark.

Before we interact with signalr, I go through a login process (mocked for now) which sets the cookie on our end. With Android, it passed those cookies in the header when doing a GET /signalr/negotiate call and when doing a GET /signalr/connect call. With the iOS app, it passes the cookies in the header in the GET /signalr/negotiate call, but doesn't pass the cookies when doing a GET /signalr/connect call!

Looking around on the internet, I though adding withCredentials: true would fix things as below:

connection.start({withCredentials:true, transport: ['webSockets']}).done(() => { 
    console.log('Now connected, connection ID=' + connection.id); 
    exampleProxy.invoke("SomeMethod").done((r) => {
      console.log("SomeMethod result",r);
    });
}).fail(() => {
    console.log('Failed'); 
});

but that still doesn't fix things. Using react-native-cookies, I've found that all my cookies have the path parameter set to "/", so that's not the issue (plus, Android works fine).

I'm still using the same trick as addressed in #11 on the XCode project.

Is there a way to add a custom header on the connection so that I can pretty much just attempt to stuff the cookie in the header in the iOS version? Is there another trick that I'm missing?

from react-native-signalr.

somoso avatar somoso commented on June 27, 2024

I've just noticed while browsing your source code that in ajax.js there is an XMLHttpRequest() object which is used to help signalr communicate - I'm wondering if that XMLHttpRequest could do with having withCredentials: true being passed in as well as setting it at the signalr level.

I'll give this a shot on my end and see if it fixes things tomorrow morning.

from react-native-signalr.

somoso avatar somoso commented on June 27, 2024

So just as a follow up, I've tried adding withCredentials: true to the XMLHttpRequest and I saw no improvements. As I was unsure if it was being sent properly, after the line request.open('GET', options.url);, I added the line request.setRequestHeader('x-react-native-header', 'soheb'); to see if my weird header would get passed along the chain - but it didn't!

Using Wireshark, I saw the header on the GET /signalr/negotiate call, but it completely vanishes on the GET /signalr/connect call.

I'm going to have to dig into ms-signalr-client and see what's going on

from react-native-signalr.

somoso avatar somoso commented on June 27, 2024

Right. Got it in the end.

Turns out that react's WebSocket implementation has an undocumented API that passes in headers: http://stackoverflow.com/questions/37246446/sending-cookies-with-react-native-websockets

So after much meddling with the source code, I decided to do a cheeky thing and just monkey patched in my own WebSockets, passing in my own cookies:

      var oldws = window.WebSocket;
      window.WebSocket = function(url) {
          return new oldws(url, '', {Cookie: cookie_string});
      }

That way, I don't need to keep patching your code nor Microsoft's SignalR code to pass in the cookies. It might be worth exposing the hidden 3rd parameter in WebSockets in your own APIs to allow people to set custom headers.


As for why it is even doing that in the first place, I've done some digging and found it's down to React Native source - in the Android side, the cookies get pulled in and passed in the header here: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java#L94

While in iOS the connect call in RCTWebSocketModule uses initWithURLRequest (https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTWebSocketModule.m#L60) but looking at the RCTSRWebSocket class there is initWithURL which handles cookies and calls initWithURLRequest (https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTSRWebSocket.m#L292) that gets completely bypassed.

I'll close this ticket, but you can re-open if you want. I'll try to keep an eye on this for a while for any extra feedback & comments.


EDIT: There is a pull request for the iOS version on React Native: facebook/react-native#10575 (comment) - it seems like it is waiting on some testing

from react-native-signalr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.