DyKnow / SignalR-ObjC

Objective-C Client for the SignalR Project works with iOS and Mac
MIT License
442 stars 213 forks source link

403 only when cookies are used #279

Closed nomorechickennuggets closed 8 years ago

nomorechickennuggets commented 8 years ago

We have an implementation of SignalR that is working perfectly fine with a Web application. When trying to use this with a native app:

class FHubConnection: SRHubConnection {
    static let shared = FHubConnection(username: "bob")
    private var hub: SRHubProxy!

    init(username: String) {
        super.init(URLString: APIRouter.baseURLString, queryString: ["username": username], useDefault: true)
        hub = createHubProxy("appHub") as! SRHubProxy
    }
}

FHubConnection.shared.start()

When we're not logged in (no cookie), we get:

2016-10-18 17:26:27.513 iOS Example[62704:1929149] WS: websocket will connect with connectionData [{"Name":"apphub"}] 2016-10-18 17:26:27.515 iOS Example[62704:1929149] WS: websocket will connect at url: https://appname.azurewebsites.net/signalr/connect?connectionData=%5B%7B%22Name%22%3A%22apphub%22%7D%5D&connectionToken=hm6tVHhpZ8bp19KwxmGSyoBxaCxclAjbAURmNYp0o0feH5k%2ByvFf2fJM99Ep25c3qviTrkja9/bJ0bhHOy4NtC/znVZO6rpNrIpoY6EvrMcTtaJW&groupsToken=&messageId=&transport=webSockets&username=bob 2016-10-18 17:26:28.366 iOS Example[62704:1929149] WS: websocket did open 2016-10-18 17:26:28.398 iOS Example[62704:1929149] WS: websocket did receive: {"C":"s-0,197DD","S":1,"M":[]}

2016-10-18 17:26:28.399 iOS Example[62704:1929149] AUTO: did set active transport to webSockets

However when we have a cookie in the request, we get the following:

2016-10-18 17:50:50.767 iOS Example[67514:1966092] WS: websocket will connect with connectionData [{"Name":"apphub"}] 2016-10-18 17:50:50.767 FStiOS Examplep[67514:1966092] WS: websocket will connect at url: https://app.azurewebsites.net/signalr/connect?connectionData=%5B%7B%22Name%22%3A%22apphub%22%7D%5D&connectionToken=8pldVoJOzAKgTFlTMGm/y%2Bh1RXhgLw99RU/nSs6cYGPZPT3PZQT7K77FMoRaLUvsHzLvLKUaMjoBfKWrhka00VHc70N7GjqMpXtdw0rFVEIP%2Bk5C&groupsToken=&messageId=&transport=webSockets&username=bob Browse: Fetched Me: Fetched => [Auth: 13076 | bob | Photographer] [Profile: 13076 | bob | Photographer] Notifications: Fetching 2016-10-18 17:50:51.539 iOS Example[67514:1966092] WS: websocket did fail with error ebbee68a-0972-4722-b3ef-321beb81f143, Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 403" UserInfo={NSLocalizedDescription=received bad response code from server 403, HTTPResponseStatusCode=403} 2016-10-18 17:50:51.539 iOS Example[67514:1966092] WS: websocket did fail while connecting 2016-10-18 17:50:51.540 iOS Example[67514:1966092] AUTO: will switch to next transport 2016-10-18 17:50:51.540 iOS Example[67514:1966092] AUTO: autoTransport will attempt to start serverSentEvents

What's notable is that the web app is working fine. The AppHub serverside does not Authenticate, so I don't know why we would be getting forbidden here.