Closed barakataboujreich closed 1 year ago
I'm not really sure what is causing it not to work but one thing I noticed is that it doesn't appear that you accept/respond to the OPTIONS
preflight request.
When it comes to CORS, some requests will trigger a preflight request.
In my nginx config I basically do:
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PUT, OPTIONS, HEAD' always;
add_header 'Access-Control-Allow-Headers' 'Accept, Content-Type, Access-Control-Allow-Origin' always;
add_header 'Content-Type' 'text/plain charset=UTF-8' always;
add_header 'Content-Length' 0 always;
return 204;
}
I'm sure you can adapt that to IIS equivilant. $http_origin
is a variable for the incoming request's Origin
header value.
Not sure if this will solve the issue with your event stream request, but I think it's worth a try.
sorry for my late reply, i tried what you suggested, didn't work. but with further debugging and analyzing we discovered that signalr is being connected, but the cookies aren't being sent, so the server is refusing the connection.
our authentication api is successfully returning a cookie to the client. but any other request that follows is not able to send a cookie. do you know a solution for this ?
Ah, cookies is a common issue with wkwebview, ever since they implemented some kind of caching mechanism or something. I don't really know all the details.
You could try reaching out to or cordova-ios channel on our slack on the cookie issue.
well for now i used this plugin to sort out our cookies problem, cordova-plugin-wkwebview-inject-cookie . i can work with only IOS 11 for now, better than nothing, till we get a proper solution.
can work with only IOS 11 for now, better than nothing
cordova-ios@6 only supports iOS 11+ anyway.
i guess this plugin documentation needs clarification or update, as they stated it works only on IOS 11. I tested it on IOS 13.5.1 and it works as it's supposed to. so maybe it could be a solution or walkaround for cookies in cordova-ios@6
I'll reopen this issue, I'm sure something can be done and we might be able and while we can't just use that plugin's codebase, we can draw inspiration from it.
That plugin requires the developer to add:
document.addEventListener('deviceready', () => {
wkWebView.injectCookie('mydomain.com/mypath');
});
I wonder if there is a way to have this done automatically.
Unfortunately I don't have mac hardware to experiment or develop the feature, but I do think it is something worth investigating.
while we can't just use that plugin's codebase, we can draw inspiration from it
Checking out this plugin it turned out not to be working correctly on iOS 13 (https://github.com/CWBudde/cordova-plugin-wkwebview-inject-cookie/issues/7#issuecomment-627413175). For the record...
i'm sorry, i do not know what is not working on your end. my testing environment is: Iphone X IOS 13.5.1
Back end: .Net 4.5
my problem was: cookies not being received on the server, which caused the back end to refuse the signal R connection.
solution that worked for me was this plugin.
how i solved it: on deviceready event
i added the following:
wkWebView.injectCookie("http://192.168.47.105:55554/WebService.asmx");
wkWebView.injectCookie("http://192.168.47.105:55554/signalr");
and config.xml:
<preference name="scheme" value="http" />
<preference name="hostname" value="192.168.47.105" />
after that our server was able to access cookies and signal R connection was successful. and from safari, went to the network tab and monitored every xhrhttprequest and was sending cookies to the server, and server was able to access those cookies.
i do not know what this plugin is doing to be honest, i have zero experience in objective-c.
but document.cookie
return empty string
but as the following photo login call returning a response cookie
and for the following two requests, the response cookie is being sent request 1 request 2
<preference name="scheme" value="http" /> <preference name="hostname" value="192.168.47.105" />
How does the scheme 'http' work for you. When I put it in config.xml. it uses the default app scheme instead.
<preference name="scheme" value="http" /> <preference name="hostname" value="192.168.47.105" />
How does the scheme 'http' work for you. When I put it in config.xml. it uses the default app scheme instead.
http
is a reserved scheme on iOS. Which is why it defaults to the app://
scheme, the cordova default.
<preference name="scheme" value="http" /> <preference name="hostname" value="192.168.47.105" />
How does the scheme 'http' work for you. When I put it in config.xml. it uses the default app scheme instead.
http
is a reserved scheme on iOS. Which is why it defaults to theapp://
scheme, the cordova default.
and If I use a custom scheme like app:// dummy cookie injection does not work for me. So all subsequent xhr request using session cookies are receiving 401. Anybody is able to use cookie injection with app custom scheme?
I've marked this issue as stale because it's been over a year with no further comments. If this is still an issue in the latest cordova-ios version and an up-to-date iOS version, please let us know. Otherwise, this issue will be closed.
Closing as stale.
Description
hello guys, we are trying to upgrade cordova-ios to 6.1.0 since uiwebview is deprecated and wont be accepted on stores anymore. we had everything working on uiwebview. i managed to make XMLHttpRequest work with null origin, and we are able to make api calls again. but we are facing a problem with signalR, it seems that it's not able to connect. i am not able to figure out the problem.
What is expected to happen?
signalR to connect normally to the server.
What does actually happen?
signal R isn't able to connect.
Information
for a start i got this call:
although the status is 200 ok, it is marked in red, and the preview shows an error occured trying to load the resource. then i get this in console:
XMLHttpRequest cannot load http://192.168.47.105:55554/signalr/abort?transport=serverSentEvents&clientProtocol=1.5&connectionToken=OC0LMC6PzDP%2BbksoG4PF3OlmAX6ScrTdg3yOxtaZFnHAspQjvqfFpDSCIWJGLNME%2FlCUg86Vpg1h12VOoR2uB0b2LyBVPbsRU%2BVo%2BNONkFIgdFfNcVahRec6xURdjwMs&connectionData=%5B%7B%22name%22%3A%22kindoohub%22%7D%5D.
now this is my config.xml:
i have these customheaders in my server Web.config
and i have this code in Global.asax.cs to handle the null origin:
and for my startup:
i tried enabling signalr cors but with no use and different error thrown about allow credentials to be different than true. i cant find the error or what is causing this problem if anyone can help me.
Environment, Platform, Device
Backend: .Net 4.5 webapi cordova: 9.0.0 cordova-ios: 6.1.0 device: iphonex device ios: 13.5.1 SignalR: 2.2.1.0
Checklist